我正在使用此代码,但问题是它在 nsdata 转换块中对 Haxcode 进行编码,我想发送相同的代码,我使用固定整数的用户 ID 获得。请帮忙。
NSData *imageData = [NSData dataWithData:UIImageJPEGRepresentation(image1, 0)];
//image.image=image1;
[Base64 initialize];
NSString *b64EncStr = [Base64 encode:imageData];
NSLog(@"encoded.%@",b64EncStr);
NSURL *url = [[NSURL alloc] initWithString:updateimageURL];
NSMutableURLRequest *req = [[NSMutableURLRequest alloc]initWithURL:url];
[req setHTTPMethod:@"POST"];
NSString *trimmed = [b64EncStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
paramDataString = [NSString stringWithFormat:@"Id=%d&FromString=%@",100,trimmed];
NSLog(@"%@",paramDataString);
NSData* aData = [paramDataString dataUsingEncoding:NSUTF8StringEncoding];
[req setHTTPBody: aData];
NSURLConnection *theConnection=[[NSURLConnection alloc]initWithRequest:req delegate:self];
if (theConnection)
{
NSMutableData *data = [[NSMutableData alloc] init];
self.receivedData=data;
[data release];
}
else {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil message:@"Check your networking configuration." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
[url release];
[req release];
它以正确的方式建立 URL 连接,但响应是服务器错误。