0

Hey, I'm working on an app for my final year project in college and something I'm struggling with is trying to use the default http client to mimic the below post, as it seems different in format to the others I have seen. The code I'm using it similar to this and has been successful at logging onto the site:

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.myurl.com/app/page.php"); 
// Add your data   
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);   
nameValuePairs.add(new BasicNameValuePair("type", "20"));
nameValuePairs.add(new BasicNameValuePair("mob", "919895865899"));
nameValuePairs.add(new BasicNameValuePair("pack", "0"));
nameValuePairs.add(new BasicNameValuePair("exchk", "1"));

try {
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        Log.d("myapp", "works till here. 2");
        try {
            HttpResponse response = httpclient.execute(httppost);
            Log.d("myapp", "response " + response.getEntity());
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

However, I'm struggling to distinguish parameters and their values from the below post and am unsure of the purpose of the number 8743499427392. Any help would be much appreciated:

(part of the post from Http Live Headers)

http://messaging.o2online.ie/con_save.osp

POST /con_save.osp -----------------------------8743499427392
Content-Disposition: form-data; name="EContactID"

 -1^
 -----------------------------8743499427392
 Content-Disposition: form-data; name="EContactIDList"


 -----------------------------8743499427392
 Content-Disposition: form-data; name="Categories"

 Synch;
 -----------------------------8743499427392
 Content-Disposition: form-data; name="ENickName"

 Test Colm Test Shannon
 -----------------------------8743499427392
 Content-Disposition: form-data; name="EAtt1"; filename=""
 Content-Type: application/octet-stream


 -----------------------------8743499427392
 Content-Disposition: form-data; name="EPMobile"

 0868617541
 -----------------------------8743499427392
 Content-Disposition: form-data; name="EMobile"


 -----------------------------8743499427392--
Colm Shannon
  • 154
  • 3
  • 4
  • 17

1 Answers1

2

This is called a multi-part format, which means that each form-field gets its own block of a multi-part request. This format is typically used for uploading files.

The -----###### line is simply the divider that splits each form field into its own section. The exact characters are listed in a HTTP header that allows the receiver to parse the body.

You can use a tool like Fiddler (www.fiddler2.com) to see this type of format in use on real-world sites.

See also: Multipart forms from C# client and Upload files with HTTPWebrequest (multipart/form-data)

Community
  • 1
  • 1
EricLaw
  • 56,563
  • 7
  • 151
  • 196
  • Hey, what did you mean when you said "The exact characters are listed in a HTTP header that allows the receiver to parse the body."? Will I somehow need to retrieve this value to successfully mimic these posts? – Colm Shannon Mar 29 '11 at 12:46
  • For the server to properly parse your request, yes, you need to include your delimiter string in the HTTP header in the same way that the browser does. – EricLaw Mar 29 '11 at 22:26
  • ok. what I'm wondering is how I go about finding this string? – Colm Shannon Mar 31 '11 at 12:30
  • Look at the HTTP headers of the request. It's in the Content-Type header. – EricLaw Apr 01 '11 at 13:59