我使用这个 php 代码为某些任务编写 java 代码
$data_array = array(
'mail'=>'****.com',
'profile_first_name' => 'Sidath'
);
$json_data = json_encode($data_array);
$request = new HTTP_Request2('**************');
$request->setMethod(HTTP_Request2::METHOD_POST)
->addPostParameter(array(
'data' => $json_data,
)
);
这是我写的java代码
URL url = new URL("*******.xml");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8\"");
String input = "{\"mail\":\"****@gmail.com\",\"profile_first_name\" : \"jjsjds\"}";
OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();
运行此 java 代码后,它会给出 http 错误 302。但 php 代码工作正常。为什么这个 java 代码返回 302