【问题标题】:could not get response for webservice even in postman即使在邮递员中也无法获得网络服务的响应
【发布时间】:2018-05-28 06:00:45
【问题描述】:

我正在实施 .svc Web 服务,但未能成功响应。请告知问题

网络服务网址是: 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

【问题讨论】:

    标签: android json postman svc


    【解决方案1】:

    我正在使用 Volley JsonObjectRequest 并且我的模型是用 Gson 库解析的。 我还实现了 WCF 网络服务。

    [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'
    

    我希望它会起作用。

    【讨论】:

      猜你喜欢
      • 2018-01-04
      • 2017-06-24
      • 2019-04-01
      • 2023-02-01
      • 2019-07-18
      • 1970-01-01
      • 1970-01-01
      • 2017-08-26
      • 1970-01-01
      相关资源
      最近更新 更多