即使在邮递员中也无法获得web服务的响应

时间:2018-05-28 06:00:46

标签: android json postman svc

我实施.svc网络服务,但无法获得成功回应。请让我知道这个问题

网络服务网址是: http://77.92.177.131/Focus8Library/TransactionService.svc/LoadVoucher

我们必须发送json输入:

json是:

"{
  ""iVoucherType"": 5635,
  ""sVoucherNo"": ""101973"",
  ""objLoadTrans"": {
    ""arrBodyIds"": null,
    ""arrBodyNames"": [
      ""Product"",
      ""Description"",
      ""Unit"",
      ""Quantity"",
      ""L-Sales Quotations"",
      ""Rate"",
      ""Gross"",
      ""Discount Amt"",
      ""Discount %"",
      ""sRemarks""
    ],
    ""arrFooterIds"": null,
    ""arrFooterNames"": [
      ""Scheme Discount"",
      ""Round Off"",
      ""Card Charges"",
      ""Special Discount""
    ],
    ""arrHeaderIds"": null,
    ""arrHeaderNames"": [
      ""sVoucherNo"",
      ""Date"",
      ""CustomerAC"",
      ""Currency"",
      ""Outlet"",
      ""Salesman"",
      ""Cost Center"",
      ""sNarration"",
      ""Delivery_Address"",
      ""Delivery_Terms"",
      ""Pay_Terms"",
      ""LPONo""
    ]
  },
  ""bByIds"": ""false""
}"                  

我们必须发送fsessionid - 应该在请求标题中添加

session id is :==>> 280520188522077721

1 个答案:

答案 0 :(得分:0)

我正在使用Volley JsonObjectRequest,我的模型用Gson库解析。 我还实现了WCF webservice。

[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "simplePostExample", BodyStyle = WebMessageBodyStyle.Bare)]

Test simplePostExample(Test test);

测试是自定义对象。

它在我的场景中完美运作。

public class CustomJsonRequest extends JsonRequest<T> {

        private Class<T> mType;
        private String mEncodedCharSetProtocol = "utf-8";

        CustomJsonRequest(int method, String url, Class<T> type, JSONObject jsonRequest,
                      Response.Listener<T> listener, Response.ErrorListener errorListener) {
            super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(), listener,
                    errorListener);
            this.mType = type;
        }


        @Override
        protected Response<T> parseNetworkResponse(NetworkResponse response) {
            try {
                String parsed;
                try {
                    if (mEncodedCharSetProtocol != null) {
                        parsed = new String(response.data, mEncodedCharSetProtocol);
                    } else {
                        parsed = new String(response.data,
                                HttpHeaderParser.parseCharset(response.headers));
                    }
                } catch (UnsupportedEncodingException e) {
                    parsed = new String(response.data);
                }
                Gson gson = new Gson();
                return Response.success(gson.fromJson(parsed, mType),HttpHeaderParser.parseCacheHeaders(response));
            } catch (Throwable e) {
                return Response.error(new ParseError(e));
            }
        }
    }

还包括Gson库

implementation 'com.google.code.gson:gson:2.8.2'

我希望它能奏效。