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 8493143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:55:32+00:00 2026-06-10T22:55:32+00:00

I’m having a problem with getting a simple output from a web service using

  • 0

I’m having a problem with getting a simple output from a web service using Android RESTful consumer. Below is my code and my output. However, I cannot seem to get a value returned from this web service. http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit

I’d greatly appreciate it if anyone can help me figuring out why it says in the SOAP message

"Server was unable to process request. ---> Data at the root level is      
invalid"

My Code Compiles And Runs Fine

public class MainActivity extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    BufferedReader in = null;
    try {
        HttpClient client = new DefaultHttpClient();
        HttpPost request = new HttpPost(
                "http://www.w3schools.com/webservices/tempconvert.asmx?op=CelsiusToFahrenheit");

        List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
        postParameters.add(new BasicNameValuePair("param1", "77"));
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
        request.setEntity(formEntity);

        HttpResponse response = client.execute(request);

        in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        StringBuffer sb = new StringBuffer("");
        String line = "";
        String NL = System.getProperty("line.separator");
        while ((line = in.readLine()) != null) {
            sb.append(line + NL);
        }
        in.close();

        String page = sb.toString();
        // Log.i(tag, page);
        System.out.println(page);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
}

My Output

09-08 14:25:25.383: I/System.out(1620): <?xml version="1.0" encoding="utf-8"?>   
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code> 
<soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text   
xml:lang="en">Server was unable to process request. ---&gt; Data at the root level is  
invalid. Line 1, position 1.</soap:Text></soap:Reason><soap:Detail /></soap:Fault> 
</soap:Body></soap:Envelope>

09-08 14:25:25.863: D/gralloc_goldfish(1620): Emulator without GPU emulation detected.
09-08 14:30:00.076: I/Choreographer(1620): Skipped 35 frames!  The application may be doing too much work on its main thread.
  • 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-06-10T22:55:33+00:00Added an answer on June 10, 2026 at 10:55 pm

    I think you should follow the steps from your provided website, from the HTTP POST sections.

    From what I can understand the request url should be http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit

    Also, the POST parameter should be Celsius=77 in your case.

    I did a simple test with curl:

    curl -d "Celsius=50" http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit
    

    and I got as response:

    <?xml version="1.0" encoding="utf-8"?>
    <string xmlns="http://tempuri.org/">122</string>
    

    which seems to be ok.

    Try this in your onCreate() method:

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    
            StrictMode.setThreadPolicy(policy);
    
    
            BufferedReader in = null;
            try {
                HttpClient client = new DefaultHttpClient();
                HttpPost request = new HttpPost(
                        "http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit");
    
                String celsius = "50";
                request.addHeader("Content-Type", "application/x-www-form-urlencoded");
    
                List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                postParameters.add(new BasicNameValuePair("Celsius", celsius));
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
                request.setEntity(formEntity);
    
                HttpResponse response = client.execute(request);
    
                in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                StringBuffer sb = new StringBuffer("");
                String line = "";
                String NL = System.getProperty("line.separator");
                while ((line = in.readLine()) != null) {
                    sb.append(line + NL);
                }
                in.close();
    
                String page = sb.toString();
                // Log.i(tag, page);
                System.out.println(page);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
    

    Where celsius is the value you want to POST.

    My output (logcat) looks like this:

    06-28 07:57:17.506: I/System.out(1847): <?xml version="1.0" encoding="utf-8"?>
    06-28 07:57:17.506: I/System.out(1847): <string xmlns="http://tempuri.org/">122</string>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm making a simple page using Google Maps API 3. My first. One marker
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.