gpt4 book ai didi

java - Ion 返回 XML 错误而期望 JSON

转载 作者:行者123 更新时间:2023-11-29 23:49:17 24 4
gpt4 key购买 nike

我正在使用 Ion 库将 JsonArray 发送到 Web 服务并获取 JSOn 输出。相同的 url 和输入在 postman 上运行良好,给出了正确的结果。但是当通过 Ion 库提供相同的 url 和输入时,它会以 xml 格式给出请求错误。

请按照我正在使用的代码帮助我摆脱这个问题

Ion.with(PracticalExam.this)
.load(url)
.setJsonArrayBody(jsonArray)
.asString()
.setCallback(new FutureCallback<String>() {
@Override
public void onCompleted(Exception e, String result)
{
String error=null;
System.out.println("RESPONSE===> "+result);
}
});

下面是我得到的回复

`���<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Request Error</title>
<style>BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}</style>
</head>
<body>
<div id="content">
<p class="heading1">Request Error</p>
<p xmlns="">The server encountered an error processing the request. Please see the <a rel="help-page" href="http://json.ezeetest.in/EZEEService.svc/help">service help page</a> for constructing valid requests to the service. The exception message is 'Incoming message for operation 'PracticalResult' (contract 'IEZEEService' with namespace 'http://tempuri.org/') contains an unrecognized http body format value 'Json'. The expected body format value is 'Raw'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.'. See server logs for more details. The exception stack trace is: </p>
<p> at System.ServiceModel.Dispatcher.HttpStreamFormatter.GetStreamFromMessage(Message message, Boolean isRequest)
at System.ServiceModel.Dispatcher.HttpStreamFormatter.DeserializeRequest(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message message, Object[] parameters)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</p>
</div>
</body>
</html>

`

我尝试按照建议进行操作,但仍然得到空结果

Ion.with(PracticalExam.this)
.load("POST",url)
.addQuery("action", "dummyAction")
.addHeader("Content-Type", "application/json")
.setJsonArrayBody(jsonArray)
.asJsonObject()
.setCallback(new FutureCallback<JsonObject>()
{
@Override
public void onCompleted(Exception e, JsonObject result)
{
pd.dismiss();
System.out.println("Result=> " + result);
System.out.println("Exception=> "+e);
}
});

最佳答案

在简单的 URI 连接中有请求的属性:

setRequestProperty("Content-Type", "application/json");

关于java - Ion 返回 XML 错误而期望 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51075157/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com