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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:30:16+00:00 2026-06-06T14:30:16+00:00

I’m writting an app which has to post some data on a webservice. To

  • 0

I’m writting an app which has to post some data on a webservice.
To do so, I used that tutorial.

The method “get” is working but not the post.

Webservice code :

[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
UriTemplate = "picture")]
public void UploadPicture(RReport report)
{
    if(report == null)
        throw new WebFaultException<string>("Bad parameter", HttpStatusCode.BadRequest);

    //other stuff
}

what is expected by the webservice should look like :

The following is an example request Json body:

{ “PictureBase64″:”String content” }

And now the android part :

//Localhost URI
String url = "http://10.0.2.2:51136/API/picture";
RestClient client = new RestClient(url);
try {
    Report r = new Report("ok");

    //Convert in json
    String report = new Gson().toJson(r);
    //What shows the log => {"PictureBase64":"ok"}
    Log.i("Json", report);
    //Add the param
    client.AddParam("report", report);

    //set the header
    client.AddHeader("Content-Type","application/json");
    client.Execute(RequestMethod.POST);
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

 String response = client.getResponse();
 Log.i("Response", response);

And now the error from the android part :

?<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Request Error</title>
        <style>BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}</style>
    </head>
    <body>
        <div id="content">
        <p class="heading1">Request Error</p>
        <p xmlns="">The server encountered an error processing the request. Please see the <a rel="help-page" href="http://10.0.2.2:51136/API/help">service help page</a> for constructing valid requests to the service.</p>
        </div>
    </body>
</html>

EDIT :
New way to call my webservice :

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(myWebservice);

StringEntity input = new StringEntity(myJson);
input.setContentType("application/json");
postRequest.setEntity(input);

HttpResponse response = httpClient.execute(postRequest);
  • 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-06T14:30:18+00:00Added an answer on June 6, 2026 at 2:30 pm

    you are setting the content type to JSON, but you aren’t posting JSON, you are posting key values pairs, where the value is a string (which happens to be JSON, but that irrelevant). does your web service want a JSON body, or form data?

    assuming you want to post parameters, not a JSON body, set your mime type to: application/x-www-form-urlencoded, and also make sure that you are URL encoding the parameters (maybe restlet does that for you, i’m not sure).

    on the other hand, if you actually just want to post a JSON body, leave the mime type as-is, and do something like,

    StringRepresentation sr = new StringRepresentation(myJsonString);
    Representation rep = client.post();
    

    also, assuming this doesn’t solve your problem, it’d be good to know the status code from the server. 404? 400? 403? assuming the web service you are using returns the right codes, it could be very helpful in finding the root cause.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.