我HttpURLConnection
用来从 Java 访问服务器。
URL: http://clicks.pureleads.com/c/E1oTzCqNzcgtN8YfNs5wg25lxQ7X8*PEqjqks**E|l9gsgSg6ZyKU7FdR0WkUDvIZ2jgG9hhb1qfSlUJpaojsCMystWBEfw6EacQ4K)zd6CtREq0PA68Uj4rPqLEsBgQdK6pgV88epNw3LF7S3X4erNQmaF26N)47Eb8H9O58bmMrEwGTBJ*avyzVCGxuyuaAoqBkOBafBru3i44S*oP74Wu4toNaTW3onZrpV9qsIqsMb3kC9J2s4RDStFqTAzH0VPlO)ZI0SWtJAchAt76suO2vTJdu6WVynplETGZD4I6DvNiQ1CSnQtSE0G2ing((
对于编码 URL,我正在使用URLEncoder.encode(url, "UTF-8");
Encoded URL:
http://clicks.pureleads.com/c/E1oTzCqNzcgtN8YfNs5wg25lxQ7X8*PEqjqks**E%7Cl9gsgSg6ZyKU7FdR0WkUDvIZ2jgG9hhb1qfSlUJpaojsCMystWBEfw6EacQ4K)zd6CtREq0PA68Uj4rPqLEsBgQdK6pgV88epNw3LF7S3X4erNQmaF26N)47Eb8H9O58bmMrEwGTBJ*avyzVCGxuyuaAoqBkOBafBru3i44S*oP74Wu4toNaTW3onZrpV9qsIqsMb3kC9J2s4RDStFqTAzH0VPlO)ZI0SWtJAchAt76suO2vTJdu6WVynplETGZD4I6DvNiQ1CSnQtSE0G2ing((
当我尝试在浏览器中打开上述 URL 时,响应代码为OK(200)
. 从 Java 中,服务器返回response code 400
.
代码片段:
URI uri = new URI("http", "clicks.pureleads.com","/c/E1oTzCqNzcgtN8YfNs5wg25lxQ7X8*PEqjqks**E|l9gsgSg6ZyKU7FdR0WkUDvIZ2jgG9hhb1qfSlUJpaojsCMystWBEfw6EacQ4K)zd6CtREq0PA68Uj4rPqLEsBgQdK6pgV88epNw3LF7S3X4erNQmaF26N)47Eb8H9O58bmMrEwGTBJ*avyzVCGxuyuaAoqBkOBafBru3i44S*oP74Wu4toNaTW3onZrpV9qsIqsMb3kC9J2s4RDStFqTAzH0VPlO)ZI0SWtJAchAt76suO2vTJdu6WVynplETGZD4I6DvNiQ1CSnQtSE0G2ing((",null);
String url = uri.toString();
serverAddress = new URL(url);
connection = (HttpURLConnection) serverAddress.openConnection();
connection.setConnectTimeout(2000);
connection.setReadTimeout(2000);
connection.connect();
还尝试了URLEncoder.encode(url,"UTF-8")
对 URL 进行编码。
提前致谢。