Search code examples
androidhttpclientgsoap

Android : HTTPCLIENT POST - Cookies Rejected


I am getting below warning frequently while running my HttpClient example

 06-05 17:43:40.568: W/ResponseProcessCookies(725): Cookie rejected:   "BasicClientCookie[version=1,name=visit,domain=.127.0.0.1,path=/,expiry=Tue Jun 05 17:53:40 IST 2012]". Domain attribute ".127.0.0.1" violates RFC 2965: effective host name does not domain-match domain attribute.

I am trying to send data to gsoap server. I have gone through this link1 link2 link3 but din't get much help. here is my code for HttpClient post code

public class newA extends Activity implements OnClickListener {

private static final String TAG = "MyPost";

private boolean post_is_running = false;

private doSomethingDelayed doSth;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    Button pushButton = (Button) findViewById(R.id.push_button);
    pushButton.setOnClickListener(this);

}

@Override
protected void onPause() {
    super.onPause();
    if (post_is_running) { // stop async task if it's running if app gets
                            // paused
        Log.v(TAG, "Stopping Async Task onPause");
        doSth.cancel(true);
    }
}

@Override
protected void onResume() {
    super.onResume();
     if (post_is_running) { // start async task if it was running previously
                            // and was stopped by   onPause()
        Log.v(TAG, "Starting Async Task onResume");
        doSth = (doSomethingDelayed) new doSomethingDelayed().execute();
        ((Button) findViewById(R.id.push_button)).setText("Resuming..");
    }
}

public void onClick(View v) {
    if (post_is_running == false) {
        post_is_running = true;
        Log.v(TAG, "Starting Async Task onClick");
        doSth = (doSomethingDelayed) new doSomethingDelayed().execute();

        ((Button) findViewById(R.id.push_button)).setText("Starting..");
    } else {
        Log.v(TAG, "Stopping Async Task onClick");
        post_is_running = false;
        doSth.cancel(true);
        ((Button) findViewById(R.id.push_button)).setText("Stopping..");
    }
}

private class doSomethingDelayed extends AsyncTask<Void, Integer, Void> {

    private int num_runs = 0;

    @Override
    protected Void doInBackground(Void... gurk) {

        while (!this.isCancelled()) {
            Log.v(TAG, "going into postData");

            long ms_before = SystemClock.uptimeMillis();
            Log.v(TAG, "Time Now is " + ms_before);

            postData();

            long ms_after = SystemClock.uptimeMillis();

            long time_passed = ms_after - ms_before;

            Log.v(TAG, "coming out of postData");
            Log.i(TAG, "RTT: " + time_passed + " ms");

            num_runs++;

            // publish to UI
            if (!this.isCancelled()) {
                publishProgress(num_runs, (int) time_passed);
            }
        }
        return null;
    }

    @Override
    protected void onCancelled() {
        Context context = getApplicationContext();
        CharSequence text = "Cancelled BG-Thread";
        int duration = Toast.LENGTH_LONG;

        Toast.makeText(context, text, duration).show();

        ((Button) findViewById(R.id.push_button))
                .setText("Stopped. Tap to Start!");
    }

    @Override
    protected void onProgressUpdate(Integer... num_runs) {
        Context context = getApplicationContext();
        CharSequence text = "Looped " + num_runs[0].toString() + " Times";
        int duration = Toast.LENGTH_SHORT;

        Toast.makeText(context,
                text + "\nRTT: " + num_runs[1].toString() + " ms", duration)
                .show();

        ((Button) findViewById(R.id.push_button)).setText(text
                + "\nTap to Stop");

    }
}

/**
 * stupid function that posts hardcoded data to hardcoded address
 */

public void postData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    // HttpPost httppost = new HttpPost("http://129.132.131.73:8880/form");
    HttpPost httppost = new HttpPost("http://192.168.1.37");
    // HttpPost httppost = new HttpPost("http://disney.com/");
    // HttpGet httppost = new HttpGet("http://192.168.1.137:8880/form");

    String resp = null;
    long time_passed = 0;
    try {
        // create data to POST
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("id", "12345"));
        nameValuePairs.add(new BasicNameValuePair("stringdata",
                "XXXXX Pvt Ltd!"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        long ms_before = SystemClock.uptimeMillis();

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

        long ms_after = SystemClock.uptimeMillis();
        time_passed = ms_after - ms_before;

        resp = response.toString();

    } catch (ClientProtocolException e) {
        Log.e(TAG, e.toString());
    } catch (IOException e) {
        Log.e(TAG, e.toString());
    }

    Log.i(TAG, "RTT inside post-data: " + time_passed);

    Log.i(TAG, resp.toString());
}

}

please let me know where is the problem .. thanks..


Solution

  • I think your HTTPClient/Android code is fine. It looks like the HTTP server is trying to send cookies for the domain ".127.0.0.1", but that's based on an IP address instead of a domain name.

    You probably need to configure your HTTP/SOAP server to believe it has a real name, one accessible from your network, instead of 127.0.0.1 or another IP address. This might also work: 37.1.168.192.in-addr.arpa

    After configuring the server, you might need to change your Java code to use that domain name (eg. new HttpPost("http://server-name.local/");).