开发者

Mimicing a browsers HTTP post request, strange format

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开发者_JS百科'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--


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜