Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6628511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:08:23+00:00 2026-05-25T22:08:23+00:00

I want to make a request to a web services http://www.w3schools.com/webservices/tempconvert.asmx and I cannot

  • 0

I want to make a request to a web services http://www.w3schools.com/webservices/tempconvert.asmx and I cannot get a OK respond and got 400 bad request instead.

Here is my AsyncTask doInBackground

protected String doInBackground(Void... params) {
    String s=null;
    try {

        restclient client1 = new restclient("http://www.w3schools.com/webservices/tempconvert.asmx");
        client1.AddParam("Celsius", "12");

        client1.AddHeader("Content-Type", "text/xml; charset=utf-8" );
        client1.AddHeader("SOAPAction", "http://tempuri.org/CelsiusToFahrenheit");


            client1.Execute(RequestMethod.POST);
            s = client1.getResponse();
            return s;
            } catch (Exception e) {

                e.printStackTrace();
            }


    return  s;       
}

I have a class for client1 that I got from a post (cant find the link for that now)

public class restclient {

public enum RequestMethod {
    GET, POST
}

private ArrayList<NameValuePair> params;
private ArrayList<NameValuePair> headers;

private String url;

private int responseCode;
private String message;

private String response;

public String getResponse() {
    return response;
}

public String getErrorMessage() {
    return message;
}

public int getResponseCode() {
    return responseCode;
}

public restclient(String url) {
    this.url = url;
    params = new ArrayList<NameValuePair>();
    headers = new ArrayList<NameValuePair>();
}

public void AddParam(String name, String value) {
    params.add(new BasicNameValuePair(name, value));
}

public void AddHeader(String name, String value) {
    headers.add(new BasicNameValuePair(name, value));
}

public void Execute(RequestMethod method) throws Exception {
    switch (method) {
    case GET: {
        // add parameters
        String combinedParams = "";
        if (!params.isEmpty()) {
            combinedParams += "?";
            for (NameValuePair p : params) {
                String paramString = p.getName() + "="
                        + URLEncoder.encode(p.getValue(), "UTF-8");
                if (combinedParams.length() > 1) {
                    combinedParams += "&" + paramString;
                } else {
                    combinedParams += paramString;
                }
            }
        }

        HttpGet request = new HttpGet(url + combinedParams);

        // add headers
        for (NameValuePair h : headers) {
            request.addHeader(h.getName(), h.getValue());
        }

        executeRequest(request, url);
        break;
    }
    case POST: {
        HttpPost request = new HttpPost(url);

        // add headers
        for (NameValuePair h : headers) {
            request.addHeader(h.getName(), h.getValue());
        }

        if (!params.isEmpty()) {
            request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
        }

        executeRequest(request, url);
        break;
    }
    }
}

private void executeRequest(HttpUriRequest request, String url) {
    HttpClient client = new DefaultHttpClient();

    HttpResponse httpResponse;

    try {
        httpResponse = client.execute(request);
        responseCode = httpResponse.getStatusLine().getStatusCode();
        message = httpResponse.getStatusLine().getReasonPhrase();

        HttpEntity entity = httpResponse.getEntity();

        if (entity != null) {

            InputStream instream = entity.getContent();
            response = convertStreamToString(instream);

            // Closing the input stream will trigger connection release
            instream.close();
        }

    } catch (ClientProtocolException e) {
        client.getConnectionManager().shutdown();
        e.printStackTrace();
    } catch (IOException e) {
        client.getConnectionManager().shutdown();
        e.printStackTrace();
    }
}

private static String convertStreamToString(InputStream is) {

    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return sb.toString();
}

}

I’ve also included access for Internet

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.android.test"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />

<uses-permission android:name="android.permission.INTERNET" />


<application android:icon="@drawable/icon" android:label="@string/app_name">
   .....         
</application>

I only get a bad request response when I tried to post. Do I need to use more parameters? I feel that the body is wrong, but I can’t find a solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:08:24+00:00Added an answer on May 25, 2026 at 10:08 pm

    EDIT: I just saw your content-type header, have you tried “application/soap+xml”? Also, SOAP required POST I believe, GET will not work, so you’re right to do POST.

    EDIT2: That client class your using isn’t going to work. You need to send a XML in the body of your POST request, wrapped in a SOAP XML wrapper. The XML needs to follow the structure of the WSDL for your endpoint. I would recommend using SOAP UI (link below) to figure out what the XML should look like. If you wanted to get fancy, you should create a class that will serialize to look exactly like the request the SOAP UI creates.

    For SOAP services you can almost always access the WSDL by adding ?WSDL to the endpoint url:
    http://www.w3schools.com/webservices/tempconvert.asmx?wsdl

    If that doesn’t work…

    How to troubleshoot web services:

    1. Download and install SoapUi and get your SOAP request working by importing your WSDL and filling in required inputs
    2. Once your request is working install fiddler or some other proxy
    3. Change the URL of your request in SoapUI to localhost:8888 or whatever the name of your machine is and the port where your proxy is running (fiddler runs on 8888 by default).
    4. Make the same working request from SoapUI but to the new URL (localhost:8888 or whatever), the request will fail, but fiddler will have captured your request
    5. Now in your android code, change the URL of the SOAP request to localhost:8888 and make the request, this will also fail but fiddler will have captured your request
    6. Look at the two requests and compare them. Start by looking at the headers and then the SOAP wrapper/xml.

    I’ve done exactly this a million times, it’s a guaranteed method to find the difference between two requests. Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I want to make a http request with a body (say file, file2,
I want to make a request to a SOAP Web Service but I don't
I want to make a http request with android. is use this: void testHTTP()
I'm trying to Add Service Reference to SharePoint web services (e.g., http://cogent-moss/_vti_bin/Webs.asmx ), but
I want to make some request from iPhone app to my web service (Rails)
I followed these instructions here: http://w3schools.com/razor/razor_example.asp NOTE: I'm using Web Matrix The example said
Hi i want to make a request for soap using above soap xml <soapenv:Envelope
Suppose you want to make an async request in JavaScript, but you want to
OK when I make a request I want all the items with the same
I'm trying to make a request/reply section in my project. I want to achieve

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.