当我使用 Java HttpUrlConnection 联系 Web 服务时,它只返回 400 Bad Request (IOException)。如何获取服务器返回的 XML 信息;它似乎不在连接的 getErrorStream 中,也不在任何异常信息中。
当我针对 Web 服务运行以下 PHP 代码时:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.myclientaddress.com/here/" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST,1 );
curl_setopt($ch, CURLOPT_POSTFIELDS,"username=ted&password=scheckler&type=consumer&id=123456789&zip=12345");
$result=curl_exec ($ch);
echo $result;
?>
Run Code Online (Sandbox Code Playgroud)
它返回以下内容:
<?xml version="1.0" encoding="utf-8"?>
<response>
<status>failure</status>
<errors>
<error name="RES_ZIP">Zip code is not valid.</error>
<error name="ZIP">Invalid zip code for residence address.</error>
</errors>
</response>
Run Code Online (Sandbox Code Playgroud)
所以我知道信息存在
我知道所有数学都是作为处理当前值所需的最大数据类型完成的,但当你横向循环时,如何明确地乘以long?我怀疑,由于溢出,下面的代码返回0.
long result = 0L;
List<Long> temp = (List<Long>) getListOfIntegers();
for (int i = 0; i < temp.size(); i++) {
result *= temp.get(i).longValue();
}
System.out.println(result);
Run Code Online (Sandbox Code Playgroud)