- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这可能是一个常见问题,但我无法弄清楚。
我有这个 URL,如果我将其插入浏览器,它会返回预期的票证详细信息,因此我知道它正在工作:
https://www.myconnectwise.net/v4_6_release/services/system_io/integration_io/processClientAction.rails?actionString=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-16%22%3F%3E%0A%3CGetTicketAction%20xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchemainstance%22%20xmlns%3Axsd%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%22%3E%0A%3CCompanyName%3Exxxxxxx%3C%2FCompanyName%3E%3CIntegrationLoginId%3Exxxxxx%3C%2FIntegrationLoginId%3E%3CIntegrationPassword%3Exxxxxx%3C%2FIntegrationPassword%3E%0A%3CSrServiceRecid%3E1921%3C%2FSrServiceRecid%3E%3C%2FGetTicketAction%3E
要获得更具可读性的版本,请访问以下 URL:
https://www.myconnectwise.net/v4_6_release/services/system_io/integration_io/processClientAction.rails
随后:
?actionString=
后面是这个 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>xxxx</CompanyName><IntegrationLoginId>xxxx</IntegrationLoginId><IntegrationPassword>xxxx</IntegrationPassword>
<SrServiceRecid>1921</SrServiceRecid></GetTicketAction>
我在将其放入代码并使其正常工作时遇到问题。
我收到此错误:
???????????????????????????????????????????????????????????????????????????????????????????? ???????????????????????????????????????????? o?????????????????????????????????????????????????????????????????????????????????????????? ???????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????o???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
com.google.gwt.xml.client.impl.DOMParseException: Failed to parse: error on line 1 at column 1: Document is empty
at com.google.gwt.xml.client.impl.XMLParserImplSafari.throwDOMParseException(XMLParserImplSafari.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.xml.client.impl.XMLParserImplSafari.parseImpl(XMLParserImplSafari.java)
at com.google.gwt.xml.client.impl.XMLParserImpl.parse(XMLParserImpl.java:278)
at com.google.gwt.xml.client.XMLParser.parse(XMLParser.java:47)
at com.google.gwt.HelpDeskTest.client.HelpDeskTest.processXML(HelpDeskTest.java:232)
at com.google.gwt.HelpDeskTest.client.HelpDeskTest$2$1.onSuccess(HelpDeskTest.java:199)
at com.google.gwt.HelpDeskTest.client.HelpDeskTest$2$1.onSuccess(HelpDeskTest.java:1)
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:232)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:258)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:412)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
at sun.reflect.GeneratedMethodAccessor29.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Thread.java:695)
在这一行:
System.out.println(line);
这是所有代码。正如您所看到的,我尝试将 serverParameters 设置为 URL 编码字符串和 xml 字符串:
package com.google.gwt.HelpDeskTest.server;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileReader;
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);
//DO I need to URL encode this???
//I’ve tried this:
//final String serverParameters= "%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-16%22%3F%3E%0A%3CGetTicketAction%20xmlns%3Axsi%3D%22http%3A%2F%2F" +
//"www.w3.org%2F2001%2FXMLSchema-instance%22%20xmlns%3Axsd%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%22%3E%0A%3CCompanyName" +
//"%3Exxxxx%3C%2FCompanyName%3E%3CIntegrationLoginId%3Exxxxx%3C%2FIntegrationLoginId%3E%3CIntegrationPassword%3Exxxxx%3C%2F" +
//"IntegrationPassword%3E%0A%3CSrServiceRecid%3E1921%3C%2FSrServiceRecid%3E%3C%2FGetTicketAction%3E";
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>xxxx</CompanyName><IntegrationLoginId>xxxx</IntegrationLoginId><IntegrationPassword>xxxx</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);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
wr.writeBytes(serverParameters);
wr.flush();
wr.close();
//process response - need to get xml response back.
InputStream stream = connection.getInputStream();
//put output stream into a string
BufferedReader br = new BufferedReader(new InputStreamReader(stream,"utf-16"));
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
}
}
}
最佳答案
我收到“服务器返回 HTTP 响应代码:500,URL:myconnectwise.net/v4_6_release/services/system_io/…”;执行代码后。因此请检查服务器(500 - 内部服务器错误)。并在将结果解析为 XML 之前分析响应代码。
关于java - HTTPURLConnection - 空响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22703192/
我一直在研究一个调用 Rest API 的 portlet。当API被调用且请求的数据不存在时,返回相应的JSON格式的错误信息(带有Bad request http code - 400),如果id
我有这个在 Windows VM 上运行的简单代码: URL url = new URL("http:xxx.xxx.xxx.xxx/api/cities.json"); HttpURLConnect
我有一个这样的代码: HttpURLConnection connection = (HttpURLConnection) loginUrl.openConnection(); connection.
Google 提供了 2 个不同的 HttpURLConnection 用法示例。 调用InputStream的close http://developer.android.com/training/
我想对自己编写的HTTP Servlet发出POST请求。通过使用URL.openConnection()方法,好的情况(HTTP响应代码200)始终可以正常工作。但是当我收到所需的错误响应代码(例如
您好,我已经开始使用 HttpUrlConnection,我有一个关于 Http 请求实际发送时间的问题。 我在某处读到,调用 getInputStream() 时会发送实际请求。不过,我已经编写了一
从 android 创建 HTTPURLConnection 时,有人对何时关闭连接和何时断开连接有任何经验吗?是否应该始终使用断开连接,以便可以从池中重用连接而不是重新创建连接?使用断开连接与关闭有
问题: 尝试“连接”时出现间歇性但频繁的故障。 代码、调试消息和堆栈跟踪如下。我看过类似的 问题解答,以及 android 开发人员帮助,但找不到 对失败的回答。 任何帮助表示赞赏。 编码: publ
我一直在尝试创建一个小的应用程序,该应用程序连接到editText中的url并返回状态代码。 这是onCreate代码: override fun onCreate(savedInstanceSta
我正在尝试创建 get 连接,但是当我读取服务器上的 header 时,我发现请求方法接收为 POST 而不是 GET 最佳答案 尝试删除此行:connection.setDoOutput(true)
我正在尝试将 x-www-form-urlencoded 格式的正文发送到我的本地 Web API。我可以毫无问题地进行 GET 。这是我所做的: String urlParameters =
我是 Android 开发新手,在互联网上进行了一些咨询后,我想出了以下代码来连接到 Url、POST 字符串内容并读取其响应。 private static java.lang.String get
我使用 HTTPUrlConnection 和 GET 方法从服务器获取数据,返回字符串大约 13k 个字符,但我只收到 1228 个字符。 有什么解决方案可以超过接收所有字符吗? 这是我的代码: U
我正在使用 HttpUrlConnection 来使用 REST 服务。当我执行 GET 时,就像下面显示的那样,我不想获取逐个字符返回的信息。我想以返回的格式获得结果。例如,在这里,我想获得一个 b
我从互联网上找到了下面的两段代码,我正在我的应用程序中使用它。 我真的不明白的一件事是,为什么没有调用 HttpUrlConnection.connect() 来建立 Http 连接(握手),并且没有
当使用下面的代码发出 get 请求时: private String get(String inurl, Map headers, boolean followredirects) throws Ma
我向我的用户提供下载文件的机会。 有时这个文件非常大,我在下载时实现一个 ProgressDialog。 好吧,如果用户点击返回,我想取消AsyncTask并关闭连接: @Ov
我正在尝试使用 Java 建立与立交桥的服务器连接。但是,当我的请求参数中有空格(例如 Bulach West)时,我总是会收到错误的请求响应。我使用的代码如下: StringBuilder cont
我使用 HttpURLConnection 按顺序向服务器 HttpServer 发出多个短请求。我期望的最大吞吐量是多少?我无法获得超过 25 条记录/秒的数据。 我需要每秒至少 5000 条记录。
我使用以下连接来恢复下载: connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); co
我是一名优秀的程序员,十分优秀!