這問(wèn)題困擾我好長(zhǎng)時(shí)間,不上傳文件就不是亂碼,傳文件就亂碼,并且Android好使;
最后聯(lián)合中間件后臺(tái)/Android客戶端/IOS客戶端,共同上傳比較,
最后在后臺(tái)捕捉時(shí)發(fā)現(xiàn),Android的提交輸出格式為:
創(chuàng)新互聯(lián)公司是一家以成都網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)、品牌設(shè)計(jì)、軟件運(yùn)維、成都網(wǎng)站營(yíng)銷、小程序App開(kāi)發(fā)等移動(dòng)開(kāi)發(fā)為一體互聯(lián)網(wǎng)公司。已累計(jì)為成都紙箱等眾行業(yè)中小客戶提供優(yōu)質(zhì)的互聯(lián)網(wǎng)建站和軟件開(kāi)發(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都是中文的,都沒(méi)有經(jīng)過(guò)編碼, 不過(guò)Android的設(shè)置了Content-Type,而IOS的ASIHttpRequest中,上傳文件時(shí)忽略了Content-Type的頭注入,導(dǎo)致后臺(tái)不識(shí)別編碼模式, 不過(guò)應(yīng)該是后臺(tái)特意對(duì)Android做過(guò)些處理, (之前Android傳文件是亂碼).現(xiàn)在問(wè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 .富文本代碼語(yǔ)言竟然沒(méi)有ObjC的???? 這也太low了吧? .算了 湊合看吧!!!!
文章題目:解決ASIHTTPsetFile上傳文件后中文亂碼問(wèn)題
網(wǎng)站地址:http://jinyejixie.com/article36/pgeesg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)、營(yíng)銷型網(wǎng)站建設(shè)、域名注冊(cè)、網(wǎng)頁(yè)設(shè)計(jì)公司、微信公眾號(hào)、移動(dòng)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)