Unable to post the data to server, getting error java.io.IOException: Server returned HTTP response code: 415

霸气de小男生 提交于 2019-12-03 21:18:59

Well, as Error 415 is already stating:

415 Unsupported Media Type

The request entity has a media type which the server or resource does not support. For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format.

Without knowing the specifications of what the server is expecting of you to send him, it's hard to tell what you are missing. It though seems as if you only want to receive data from the server and not send him anything.

By setting uc.setRequestProperty("Content-Type", "application/xml"); you tell the server that you hand him over some XML data (which you don't) and he probably also wouldn't expect this, so he's giving you that error.

As your sending some urlencoded data in your POST data, try setting this to:

uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!