# Pragma mark Weibo page: sendstatus-(void) sendstatus {If ([self. textview. text isequaltostring: @ ""]) {uialertview * alter = [[uialertview alloc] initwithtitle: @ "prompt" message: @ "You didn't enter anything" delegate: Nil cancelbuttontitle: @ "OK" otherbuttontitles: nil, nil]; [alter show];} else if ([self textlength: Self. textview. text]> 140) {uialertview * alter = [[uialertview alloc] initwithtitle: @ "prompt" message: @ "input text greater than 140" delegate: Nil cancelbuttontitle: @ "OK" otherbuttontitles: nil, nil]; [alter show];} If (self. imageview) {// HTTP multipart/form-Data Request analysis nsstring * status = self. textview. text; nsdata * dataimg = uiimagejpegrepresentation (self. imageview. image, 0.5); nsstring * accesstoken = [accounttool implements accounttool]. currentacount. accesstoken; nsstring * urlstr = @ "https://upload.api.weibo.com/2/statuses/upload.json"; nsurl * url = [nsurl urlwithstring: urlstr]; nsmutableurlrequest * request = [nsmutableurlrequest requestwithurl: url]; [Request sethttpmethod: @ "Post"]; // content-Disposition: Form-data; access_token = % @; status = % @; PIC = % @ nsstring * nextrow = @ "\ r \ n"; nsstring * Boundry = [nsstring stringwithformat: @ "------ % @", @ (INT) [[nsdate date] timeintervalsince1970]). description]; nsstring * Start = [@ "--" stringbyappendingstring: Boundry]; nsstring * end = [@ "--" stringbyappendingformat: @ "% @ --", Boundry]; nsstring * acctokentype = @ "content-Disposition: Form-data; name = \" access_token \ ""; nsstring * statustype = @ "content-Disposition: Form-data; name = \ "status \" "; nsstring * imagetype = @" content-Disposition: Form-data; name = \ "pic \"; filename = \ "shell.png \""; nsstring * value = [@ "multipart/form-Data" stringbyappendingformat: @ "; boundary = % @", Boundry]; [Request setvalue: Value forhttpheaderfield: @ "Content-Type"]; nsmutabledata * bodydata = [nsmutabledata data]; // accesstoken [bodydata appenddata: [start datausingencoding: Encrypted]; [bodydata appenddata: [nextrow handle: response]; [bodydata appenddata: [acctokentype datausingencoding: Required]; [bodydata appenddata: [nextrow handle: Required]; [bodydata appenddata: [nextrow datausingencoding: Required]; [bodydata appenddata: [accesstoken datausingencoding: Beijing]; [bodydata appenddata: [nextrow upload: Beijing]; // status [bodydata appenddata: [start datausingencoding: Beijing]; [bodydata appenddata: [nextrow upload: Unknown]; [bodydata appenddata: [statustype datausingencoding: Unknown]; [bodydata appenddata: [nextrow upload: Unknown]; [bodydata appenddata: [nextrow datausingencoding: Unknown]; [bodydata appenddata: [Status datausingencoding: Unknown]; [bodydata appenddata: [nextrow datausingencoding: Unknown]; // PIC [bodydata appenddata: [start sequence: sequence]; [bodydata appenddata: [nextrow datausingencoding: sequence]; [bodydata appenddata: [imagetype datausingencoding: sequence]; [bodydata appenddata: [nextrow sequence: [bodydata appenddata: [@ "Content-Type: image/PNG" datausingencoding: encoding]; [bodydata appenddata: [nextrow datausingencoding: nsutf8stringencoding]; [bodydata appenddata: [nextrow datausingencoding: Batch]; [bodydata appenddata: dataimg]; [bodydata appenddata: [nextrow handle: Batch]; [bodydata appenddata: [end transaction: nsutf8stringencoding]; // nsstring * bodystring = [nsstring stringwithformat: @ "content-Disposition: Form-data; access_token =%@; Status =% @; PIC = % @ ", [accounttool implements accounttool]. currentacount. accesstoken, status, dataimg]; // nsdata * Data = [bodystring datausingencoding: Required]; [Request sethttpbody: bodydata]; afjsonrequestoperation * op = [afjsonrequestoperation condition: Request success: ^ (nsurlrequest * request, nshttpurlresponse * response, Id JSON) {nslog (@ "sent successfully =%@", JSON ); // mbprogresshud * HUD = [mbprogresshud] // The message sending cancellation page [self failed: Yes completion: Nil];} failure: ^ (nsurlrequest * request, nshttpurlresponse * response, nserror * error, Id JSON) {nslog (@ "error = % @", error) ;}]; [op start];} else {# warning sends the nsstring * status = self. textview. text; nsstring * urlstr = @ "https://api.weibo.com/2/statuses/update.json"; nsurl * url = [nsurl urlwithstring: urlstr]; nsmutableurlrequest * request = [nsmutableurlrequest requestwithurl: url]; [Request sethttpmethod: @ "Post"]; nsstring * bodystring = [nsstring stringwithformat: @ "% =%@ & Status =%@", kaccesstoken, [accounttool implements accounttool]. currentacount. accesstoken, status]; nsdata * Data = [bodystring datausingencoding: Required]; [Request sethttpbody: Data]; afjsonrequestoperation * op = [afjsonrequestoperation response: Request success: ^ (nsurlrequest * request, nshttpurlresponse * response, Id JSON) {// nslog (@ "sent successfully =%@", JSON); // cancel sending after successful sending page [self dismissviewcontrolleranimated: Yes completion: nil];} failure: ^ (nsurlrequest * request, nshttpurlresponse * response, nserror * error, Id JSON) {nslog (@ "error = % @", error) ;}]; [op start] ;}}
Effect