Using NSURLRequest to pass key-value pairs to PHP script with POST

后端 未结 6 2077
灰色年华
灰色年华 2021-01-31 20:51

I\'m fairly new to objective-c, and am looking to pass a number of key-value pairs to a PHP script using POST. I\'m using the following code but the data just doesn\'t seem to b

6条回答
  •  南方客
    南方客 (楼主)
    2021-01-31 21:03

    This is wrong:

    [NSData dataWithBytes:[post UTF8String] length:[post length]]
    

    The length should be expressed in bytes not in count of UTF8 characters. Instead of this line you should use:

    NSData *data = [post dataUsingEncoding: NSUTF8StringEncoding]; 
    

提交回复
热议问题