// The Demarcation Line identifier nsstring * identifier = @ "aab03x"; // initialize the request nsmutableurlrequest * request = [nsmutableurlrequest requestwithurl: [nsurl urlwithstring: url] cachepolicy: Required timeinterval: 10]; // demarcation line -- aab03x nsstring * mpboundary = [[nsstring alloc] initwithformat: @ "-- % @", twitterfon_form_boundary]; // Terminator aab03x -- nsstring * endmpboundary = [[nsstring alloc] Initwithformat: @ "% @ --", mpboundary]; // The image uiimage * image to be uploaded = [Params objectforkey: @ "pic"]; // obtain the image's data nsdata * Data = uiimagepngrepresentation (image); // The HTTP body string nsmutablestring * Body = [[nsmutablestring alloc] init]; // nsarray * keys = [Params allkeys]; // traverses keys for (INT I = 0; I <[Keys count]; I ++) {// obtain the current key nsstring * Key = [Keys objectatindex: I]; // if the key is not pic, the value is of the character type, such as name: Boris If (! [Key isequaltostring: @ "pic"]) {// Add a line break, line feed [Body appendformat: @ "% @ \ r \ n", mpboundary]; // Add the field name, for two rows [Body appendformat: @ "content-Disposition: Form-data; name = \ "% @ \" \ r \ n ", key]; // Add the field value [Body appendformat: @ "% @ \ r \ n", [Params objectforkey: Key] ;}/// add a line break, line feed [Body appendformat: @ "% @ \ r \ n", mpboundary]; // specifies a picic field. The file name is boris.png [Body appendformat: @ "content-Disposition: Form-data; name = \" pic \"; filename = \ "boris.png \" \ r \ n "]; // declare the format of the uploaded file [Body appendformat: @" Content-Type: image/PNG \ r \ n "]; // declaration Terminator: -- aab03x -- nsstring * end = [[nsstring alloc] initwithformat: @ "\ r \ n % @", endmpboundary]; // declare myrequestdata to put the HTTP body nsmutabledata * myrequestdata = [nsmutabledata data]; // convert the body string to a binary string in utf8 format [myrequestdata appenddata: [Body datausingencoding: nsutf8stringencoding]; // Add the image data to [myrequestdata appenddata: Data]; // Add the terminator -- aab03x -- [myrequestdata appenddata: [end datausingencoding: nsutf8stringencoding]; // set the value of Content-Type in httpheader nsstring * content = [[nsstring alloc] initwithformat: @ "multipart/form-data; boundary = % @", twitterfon_form_boundary]; // set httpheader [Request setvalue: Content forhttpheaderfield: @ "Content-Type"]; // set Content-Length [Request setvalue: [nsstring stringwithformat: @ "% d ", [myrequestdata length] forhttpheaderfield: @ "Content-Length"]; // set HTTP body [Request sethttpbody: myrequestdata]; // HTTP method [Request sethttpmethod: @ "Post"]; // establish a connection and set the proxy nsurlconnection * conn = [[nsurlconnection alloc] initwithrequest: Request delegate: Self]; // set the data if (conn) {mresp ****** edata = [[nsmutabledata data] retain] to accept resp ***** E;}