Skip to main content
deleted 186 characters in body; edited tags
Source Link
Brock Adams
  • 13k
  • 5
  • 39
  • 64

post method to stackexchange api Question up-voting is not working from my code?

I am trying to upvote a question using the stackexchange apiStack Exchange API in android. using, via the url https://api.stackexchange.com/2.2/questions/{questionID}/upvote/2.2/questions/{questionID}/upvote route.

butBut in the log its, it's just showing something like this org.apache.http.message.BasicHttpResponse@33b2c539:

org.apache.http.message.BasicHttpResponse@33b2c539

API link for upvote a question is https://api.stackexchange.com/docs/upvote-question

When I am tryingtry it from api link its workingthe API doc page it works, but not with the code.

Find below thefrom my code below:

String url= "https://api.stackexchange.com/2.2/questions/"+questionId+"/upvote";

          String url= "https://api.stackexchange.com/2.2/questions/"+questionId+"/upvote";

HttpClient httpClient = new DefaultHttpClient ();
            HttpPost httpPost = new HttpPost (url.toString () ); 

            List<NameValuePair> nameValuePair = new ArrayList<NameValuePair> (2);

            nameValuePair.add (new BasicNameValuePair ("key", key) );
            nameValuePair.add (new BasicNameValuePair ("access_token", accessToken) );

            try {
                    httpPost.setEntity (new UrlEncodedFormEntity (nameValuePair) );
            } catch (UnsupportedEncodingException e) {
                    e.printStackTrace ();
            }
            // making request

            try {
                   response = httpClient.execute (httpPost);
                    Log.d ("Http Post Response:", response.toString () );
            } catch (ClientProtocolException e) {
                    e.printStackTrace ();
            } catch (IOException e) {
                    e.printStackTrace ();
            }

post method to stackexchange api

I am trying to upvote a question using the stackexchange api in android. using the url https://api.stackexchange.com/2.2/questions/{questionID}/upvote

but in the log its just showing something like this org.apache.http.message.BasicHttpResponse@33b2c539

API link for upvote a question is https://api.stackexchange.com/docs/upvote-question

When I am trying from api link its working, but not with the code.

Find below the code below:

String url= "https://api.stackexchange.com/2.2/questions/"+questionId+"/upvote";

            HttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url.toString()); 

            List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);

            nameValuePair.add(new BasicNameValuePair("key", key));
            nameValuePair.add(new BasicNameValuePair("access_token", accessToken));

            try {
                    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
            } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
            }
            // making request

            try {
                   response = httpClient.execute(httpPost);
                    Log.d("Http Post Response:", response.toString());
            } catch (ClientProtocolException e) {
                    e.printStackTrace();
            } catch (IOException e) {
                    e.printStackTrace();
            }

Question up-voting is not working from my code?

I am trying to upvote a question using the Stack Exchange API in android, via the /2.2/questions/{questionID}/upvote route.

But in the log, it's just showing something like:

org.apache.http.message.BasicHttpResponse@33b2c539

API link for upvote a question is https://api.stackexchange.com/docs/upvote-question

When I try it from the API doc page it works, but not from my code.

String url= "https://api.stackexchange.com/2.2/questions/"+questionId+"/upvote";

HttpClient httpClient = new DefaultHttpClient ();
HttpPost httpPost = new HttpPost (url.toString () ); 

List<NameValuePair> nameValuePair = new ArrayList<NameValuePair> (2);

nameValuePair.add (new BasicNameValuePair ("key", key) );
nameValuePair.add (new BasicNameValuePair ("access_token", accessToken) );

try {
        httpPost.setEntity (new UrlEncodedFormEntity (nameValuePair) );
} catch (UnsupportedEncodingException e) {
        e.printStackTrace ();
}
// making request

try {
       response = httpClient.execute (httpPost);
        Log.d ("Http Post Response:", response.toString () );
} catch (ClientProtocolException e) {
        e.printStackTrace ();
} catch (IOException e) {
        e.printStackTrace ();
}
Source Link
Sudheer
  • 123
  • 2

post method to stackexchange api

I am trying to upvote a question using the stackexchange api in android. using the url https://api.stackexchange.com/2.2/questions/{questionID}/upvote

but in the log its just showing something like this org.apache.http.message.BasicHttpResponse@33b2c539

API link for upvote a question is https://api.stackexchange.com/docs/upvote-question

When I am trying from api link its working, but not with the code.

Find below the code below:

String url= "https://api.stackexchange.com/2.2/questions/"+questionId+"/upvote";

            HttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url.toString()); 

            List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);

            nameValuePair.add(new BasicNameValuePair("key", key));
            nameValuePair.add(new BasicNameValuePair("access_token", accessToken));

            try {
                    httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
            } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
            }
            // making request

            try {
                   response = httpClient.execute(httpPost);
                    Log.d("Http Post Response:", response.toString());
            } catch (ClientProtocolException e) {
                    e.printStackTrace();
            } catch (IOException e) {
                    e.printStackTrace();
            }