真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

解決ASIHTTPsetFile上傳文件后中文亂碼問題

這問題困擾我好長時間,不上傳文件就不是亂碼,傳文件就亂碼,并且Android好使;
最后聯(lián)合中間件后臺/Android客戶端/IOS客戶端,共同上傳比較,
最后在后臺捕捉時發(fā)現(xiàn),Android的提交輸出格式為:

創(chuàng)新互聯(lián)公司是一家以成都網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計、品牌設(shè)計、軟件運維、成都網(wǎng)站營銷、小程序App開發(fā)等移動開發(fā)為一體互聯(lián)網(wǎng)公司。已累計為成都紙箱等眾行業(yè)中小客戶提供優(yōu)質(zhì)的互聯(lián)網(wǎng)建站和軟件開發(fā)服務(wù)。


--PfyXAYcEcmd3GqueWEk6hXUWXfm-KrG4XNEQContent-Disposition: form-data; name="companyName"Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit


公司名


IOS的提交輸出格式為:
--0xKhTmLbOuNdArY-C14CFE75-F1D5-4E68-BFDB-93957E2DDCEFContent-Disposition: form-data; name="companyName"


公司名


發(fā)現(xiàn)post的Value都是中文的,都沒有經(jīng)過編碼, 不過Android的設(shè)置了Content-Type,而IOS的ASIHttpRequest中,上傳文件時忽略了Content-Type的頭注入,導(dǎo)致后臺不識別編碼模式, 不過應(yīng)該是后臺特意對Android做過些處理, (之前Android傳文件是亂碼).現(xiàn)在問題解決了!!

下面是代碼修改處:


在ASIFormDataRequest 中的 - (void)buildMultipartFormDataPostBody 方法修改

高亮處為修改代碼:



- (void)buildMultipartFormDataPostBody {#if DEBUG_FORM_DATA_REQUEST[self addToDebugBody:@"\r\n==== Building a multipart/form-data body ====\r\n"];#endifNSString *charset = (NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding([selfstringEncoding]));// We don't bother to check if post data contains the boundary, since it's pretty unlikely that it does.CFUUIDRef uuid =CFUUIDCreate(nil);NSString *uuidString = [(NSString*)CFUUIDCreateString(nil, uuid)autorelease];CFRelease(uuid);NSString *stringBoundary = [NSStringstringWithFormat:@"0xKhTmLbOuNdArY-%@",uuidString];[selfaddRequestHeader:@"Content-Type"value:[NSStringstringWithFormat:@"multipart/form-data; charset=%@; boundary=%@", charset, stringBoundary]]; [selfappendPostString:[NSStringstringWithFormat:@"--%@\r\n",stringBoundary]];// Adds post dataNSString *endItemBoundary = [NSStringstringWithFormat:@"\r\n--%@\r\n",stringBoundary];NSUInteger i=0;for (NSDictionary *valin [selfpostData]) { [selfappendPostString:[NSStringstringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\nContent-Type:text/plain; charset=UTF-8\r\n\r\n",[valobjectForKey:@"key"]]]; [selfappendPostString:[valobjectForKey:@"value"]]; i++;if (i != [[selfpostData]count] || [[selffileData]count] >0) {//Only add the boundary if this is not the last item in the post body [selfappendPostString:endItemBoundary]; } }// Adds files to upload i=0;for (NSDictionary *valin [selffileData]) { [selfappendPostString:[NSStringstringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"%@\"\r\n", [valobjectForKey:@"key"], [valobjectForKey:@"fileName"]]]; [selfappendPostString:[NSStringstringWithFormat:@"Content-Type: %@\r\n\r\n", [valobjectForKey:@"contentType"]]];id data = [valobjectForKey:@"data"];if ([dataisKindOfClass:[NSStringclass]]) { [selfappendPostDataFromFile:data]; }else { [selfappendPostData:data]; } i++;// Only add the boundary if this is not the last item in the post bodyif (i != [[selffileData]count]) { [selfappendPostString:endItemBoundary]; } } [selfappendPostString:[NSStringstringWithFormat:@"\r\n--%@--\r\n",stringBoundary]];#if DEBUG_FORM_DATA_REQUEST[self addToDebugBody:@"==== End of multipart/form-data body ====\r\n"];#endif}

**** 51cto  .富文本代碼語言竟然沒有ObjC的????   這也太low了吧?  .算了 湊合看吧!!!!


文章題目:解決ASIHTTPsetFile上傳文件后中文亂碼問題
轉(zhuǎn)載注明:http://weahome.cn/article/pgeesg.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部