httpclient: got status 200 amen! now what?

shamed fred

I am new to programming, please have patience - I successfully done a POST to a web service, but now I want to see the data I got back, how do that? Here is my code:

try {
            String data =  "{\"params\":{\"stopName\":\"%lauro linhares%\"}}";

            CredentialsProvider credProvider = new BasicCredentialsProvider();
            credProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
                new UsernamePasswordCredentials("WKD4N7YMA1uiM8V", "DtdTtzMLQlA0hk2C1Yi5pLyVIlAQ68"));
            //
            DefaultHttpClient http = new DefaultHttpClient();
            http.setCredentialsProvider(credProvider);

            HttpPost post = new HttpPost("https://api.appglu.com/v1/queries/findRoutesByStopName/run");
            try {
                post.setEntity(new StringEntity(data, "UTF8"));
            } catch (UnsupportedEncodingException e) {
                System.out.println( "UnsupportedEncoding: "+ e);
            }

           post.addHeader("Content-Type", "application/json");
           post.addHeader("X-AppGlu-Environment", "staging");

           HttpResponse response = http.execute(post);

            System.out.println("hi! This is what we get back:"+response.getStatusLine().toString()+", "+response.getEntity().toString());
            //Hi! This is what we get back:HTTP/1.1 200 OK, org.apache.http.conn.BasicManagedEntity@4246cb88

// got status 200, which is good, but what can
//  I write next to see the 
//data i got back from web service ?



        } catch (ClientProtocolException e) {
            //
            System.out.println( "nadir Client protocol exception" + e);
        } catch (IOException e) {
            //  
            System.out.println( "nadir IOException"+ e);
        }
Kamil Kłys

Try to use:

String str =  EntityUtils.toString(response.getEntity());

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

HTTP Status 200 with warnings?

From Dev

Status 200 = HttpPut works?

From Dev

What cause "Error: Uncaught (in promise): Response with status:200 for Url:null" to show up?

From Dev

Where can I find explicit documentation on what's NOT covered by Status Code 200?

From Dev

HttpClient no success status code

From Dev

I got a HTML & CSS progress bar. what i need now is that it should load a page on complete. any ways?

From Dev

IIS logs 200 status but returns 500 status

From Dev

always returns status code 200

From Dev

HttpClient GetStreamAsync and HTTP status codes?

From Dev

Deprecated HttpClient, now using apache-httpclient-4.3.x

From Dev

RubyForge dead - now what?

From Dev

Created Adview, now what?

From Dev

Grub - what now

From Dev

No sudoers - what now?

From Dev

What is Unix now?

From Dev

Receiving final status code 200 but their are 301-> 302-> 200

From Dev

MockMVC and Mockito returns Status expected <200> but was <415>

From Dev

How to cache Only http status 200 in scrapy?

From Dev

how to redirect_to and return a 200 status code

From Dev

How to get body when status is not 200?

From Dev

How to write only logs with 200 status

From Dev

HTTP status code 200 vs 202

From Dev

DELETE Request not working , Returns status code 200

From Dev

Failed asserting the HTTP status code is 200 not 500

From Dev

AJAX call returns status 200 but no content

From Dev

AJAX ReadyState 4 Status 200 but responseText undefined

From Dev

Phoenix return 200 status code for POST

From Dev

Spring returns 401 instead of 200 status

From Dev

WebMvcTest of @Controller with @RequestParam and status is not 200, but 400

Related Related

HotTag

Archive