0

I want to send data to server from client(Android), below is my format

http://101.34.45.45/rawData?data={"userId":"guest1","timestamp":"2010-07-01 08:58:23","wifi":[{"ssid":"guest","rssi":"40"},{"ssid":"guest1","rssi":"80"}]}, 

i'm trying series of trial but no use, how this can be done?

Janusz
  • 187,060
  • 113
  • 301
  • 369
Apache
  • 1,796
  • 9
  • 50
  • 72
  • 2
    Just from a strictly draconian point of view, you should never push data to the server as part of the url. Hence the name, GET operations should only retrieve data, never make changes to data. That is reserved for POST operations – Chris Thompson Jul 06 '10 at 04:28
  • Are you properly escaping the URL? – bhups Jul 06 '10 at 04:35

2 Answers2

0

Library used: http://loopj.com/android-async-http/

private OnClickListener login = new OnClickListener() {

public void onClick(View view) {

    AsyncHttpClient myClient = new AsyncHttpClient();
    myClient.get(URL, null);
    myClient.setCookieStore(myCookieStore);
    myClient.setCookieStore(myCookieStore);
    String username = "";
    String password = "";
    RequestParams params1 = new RequestParams();
    params1.put("username", username);
    params1.put("password", password);
    pd = ProgressDialog.show(this, "", "Signing In...");
    myClient.post(URL, params1,
            new AsyncHttpResponseHandler() {
                @Override
                public void onSuccess(String response) {
                    System.out.println("response" + response);
                    pd.dismiss();
                    if (response.contains("<!--Authorized-->")) {
                    }
                    else {
                        pd.dismiss();
                        Context mContext = SigninActivity.this;
                        notMatchDialog = new Dialog(mContext);
                        notMatchDialog.setContentView(R.layout.loginfaileddialoglayout);
                        notMatchDialog.setTitle("Login failed");
                        dismissDialogButton = (Button) notMatchDialog.findViewById(R.id.dismissDialogButton);
                        dismissDialogButton.setOnClickListener(dismissDialog);
                        notMatchDialog.show();
                    }
                }

                @Override
                public void onFailure(Throwable e, String response) {
                    // TODO Need to figure out different failures and try to help the user.
                }
            });
}
};
Noman Arain
  • 1,172
  • 4
  • 19
  • 45
0

Without your code it is difficult to assess whether you are going through the process correctly, but based on what you've given us, you aren't properly encoding the data. You will need to URL encode the data before appending to the url. To do this in java, use the URLEncoder class (see the javadoc for that class here).

To do this with your code, it would look something like

String url = "http://101.34.45.45/rawData?data=";
String params = URLEncoder.encode("{\"userId\":\"guest1\",\"timestamp\":\"2010-07-01 08:58:23\",\"wifi\":[{\"ssid\":\"guest\",\"rssi\":\"40\"},{\"ssid\":\"guest1\",\"rssi\":\"80\"}]}",  "UTF-8");
url = url+params;
//do the HTTP operation

*Note, for completeness, the W3C and the javadoc advocate not using UTF-8. I used it here simply to generate some sample code.

If that doesn't solve your problem, please post your code so we can see what you're trying to do.

Chris Thompson
  • 35,167
  • 12
  • 80
  • 109