다른 제공 업체의 API (Google은 헬프 데스크 제공 업체를 전환 함)에서 작동하도록 일부 작동 코드를 수정합니다.HTTPURLConnection이 횡설수설하는 답글
나는 올바른 길을 가고 있는지를보기 위해 돌아 오는 XML을 보려고 노력하고 있지만, 돌아 오는 것이 모두 횡설수설하는 것을 볼 수 있습니다. this 질문을 보았지만 이러한 대답이 내 상황에 어떻게 적용될 수 있는지 파악할 수 없습니다.
while ((line = br.readLine()) != null) {
System.out.println(line);
}
내 질문은 : 내가 여기에 콘솔에서 돌아 오는 XML을 읽을 수 있었다 다른 API를 사용할 때
내가 정확히 기억한다면, 내가 다른 스트림을 읽을 수있는 방법이 있나요 그래서 내가 다시오고있는 XML을 읽을 수있는 또 다른 문제가 있습니까?
나는이 모든 것에 매우 환영 받는다. 자세한 내용은 아래에 나와 있습니다.
코드 :
package com.google.gwt.HelpDeskTest.server;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.gwt.HelpDeskTest.client.HelpDeskTestService;
import com.google.gwt.HelpDeskTest.shared.HelpDeskTestException;
@SuppressWarnings("serial")
public class HelpDeskTestImpl extends RemoteServiceServlet implements
HelpDeskTestService {
@Override
public String postToRemoteServer(String serviceUrl)
throws HelpDeskTestException {
try {
final String serverPath= "https://www.myconnectwise.net/v4_6_release/services/system_io/integration_io/processClientAction.rails";
System.out.println(serverPath);
final String serverParameters= "<?xml version=%221.0%22 encoding=%22utf-16%22?>" +
"<GetTicketAction xmlns:xsi=%22http://www.w3.org/2001/XMLSchema-instance%22 xmlns:xsd=%22http://www.w3.org/2001/XMLSchema%22>" +
"<CompanyName>xxxxxx</CompanyName><IntegrationLoginId>xxxxxxx</IntegrationLoginId><IntegrationPassword>xxxxxx</IntegrationPassword>" +
"<SrServiceRecid>1921</SrServiceRecid></GetTicketAction>";
System.out.println(serverParameters);
//Open HttpURLConnection:
URL url = new URL(serverPath);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(10000); //added this to see if I can address the timeout issue.
connection.setReadTimeout(10000);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("charset", "utf-16");
connection.setRequestProperty("Content-Length", "" + Integer.toString(serverParameters.getBytes().length));
connection.setUseCaches (false);
//connection.setChunkedStreamingMode(0);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(serverParameters);
wr.flush();
wr.close();
//process response - need to get xml response back.
//this was the working line of code:
InputStream stream = connection.getInputStream();
//put output stream into a string
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
String result = "";
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
result+= line;
}
br.close();
connection.disconnect();
System.out.println(result);
return result;
} catch (final Exception e) {
System.out.println(e.getMessage());
throw new HelpDeskTestException();
//handle timeout error
}
}
}
이 내가 전송을 시도하고있어 XML입니다. 필자는 회사의 API 테스터를 통해 테스트를 실시했으며 작동하는지 확인하고 xml을 보내 응답합니다.
<?xml version="1.0" encoding="utf-16"?>
<GetTicketAction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CompanyName>xxxxxx</CompanyName>
<IntegrationLoginId>xxxxxx</IntegrationLoginId>
<IntegrationPassword>xxxxx</IntegrationPassword>
<SrServiceRecid>1921</SrServiceRecid>
</GetTicketAction>
시도'connection.getContent()' – anttix