---
title: "IOS http 请求参数中中文编码"
author: "jguangyou"
date: "2012-12-08T18:11:52Z"
tags: []
categories: ["移动开发"]
slug: "ios-http"
draft: false
lastmod: "2012-12-08T18:11:52Z"
id: 1744223
url: "https://deep-fish.iteye.com/blog/1744223"
---

在使用NSURLRequest 进行http的网络访问的时候，如果(http://xxx.xxx.xx?xx=xx&xx=你好）请求参数中有中文的话，需要对字符串进行一次编码，否则你使用字符串创建NSURL的时候，返回的是空（就是这么变态）。那如何编码呢？

NSString \*urlStrl = \[\[@"your url and param"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],这样以后再创建NSURL就行了，原理吗，我就不讲了，欢迎留言哈！！！