0

I have a problem using Volley with GSON. There is no error/exception but the result returned by webservice is always null.

This is my webservice setting :

Status
200 OK Show explanation Loading time: 59
Request headers 
CSP: active
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36
Content-Type: application/x-www-form-urlencoded 
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,id;q=0.6
Response headers 
Date: Wed, 24 Jun 2015 02:37:06 GMT 
Server: Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.5.19 
X-Powered-By: PHP/5.5.19
Content-Length: 81 
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8  

I'm sure the webservice is working fine, so the problem is in the Java code.

This is my custom request, taken from here :

@Override
protected Response<T> parseNetworkResponse(NetworkResponse response) {
    try {
        Log.e("gson", "test");
        String json = new String(
                response.data,
                HttpHeaderParser.parseCharset(response.headers));
        Response result = Response.success(
                gson.fromJson(json, gsonClass),
                HttpHeaderParser.parseCacheHeaders(response));
        return result;
    } catch (UnsupportedEncodingException e) {
        Log.e("gson", e.getLocalizedMessage()); //never printed
        return Response.error(new ParseError(e));
    } catch (JsonSyntaxException e) {
        Log.e("gson", e.getLocalizedMessage()); //never printed
        return Response.error(new ParseError(e));
    }
}

And this is how i call the Volley, the Customer in onResponse is null :

        RequestQueue queue = Volley.newRequestQueue(getActivity());
        String url = "https://sister-8.tafinance.com/cust_gathering/index.php/customer/get/format/json";
        final Map<String,String> header = new HashMap<String, String>();
        //header.put("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        header.put("name", "test1");
        header.put("born_date", "1970-06-15 00:00:00.000");

        GsonRequest request = new GsonRequest(Request.Method.POST, url, Customer.class, header,
                new Response.Listener<Customer>()
                {
                    @Override
                    public void onResponse(Customer customer) {
                        txtTest.setText(customer.getName());
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        txtTest.setText("" + volleyError.getMessage());
                    }
                }
        );

        queue.add(request);

Please kindly help me. Thanks a lot for your help.

Blaze Tama
  • 10,828
  • 13
  • 69
  • 129

1 Answers1

0

What kind of web server do you use? Usually underscore is not accepted for http header field name. (born_date (x), Born-Date(o) Why underscores are forbidden in HTTP header names, https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Field_names)

You can also change settings of web server to accept underscore for http header field name. (Refer to http://nginx.org/en/docs/http/ngx_http_core_module.html#underscores_in_headers)

Community
  • 1
  • 1
Sinhyeok
  • 46
  • 4