0

如何使用加密为 HTTP 参数的注册详细信息将 HTTP POST 请求发布到 PHP 服务器。您可以根据我的要求向我发布示例代码吗?

4

2 回答 2

0

你可以使用ASIHTTPRequest,你可以这样:

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:someUrl];
[request setRequestMethod:@"POST"];
[request setPostValue:@"..." forKey:@"user"];
[request setPostValue:@"..." forKey:@"password"];
[request setDelegate:self];
[request startAsyncrhonous];

有请求的委托方法,例如请求完成或失败

- (void)requestFinished:(ASIHTTPRequest *)request 
{
   NSLog(@"Response %d ==> %@", request.responseStatusCode, [request responseString]);
}

- (void)requestFailed:(ASIHTTPRequest *)request 
{
   NSLog(@"Response %d ==> %@", request.responseStatusCode, [request responseString]);
}

您可以随时下载ASIHTTPRequest,也可以访问文档以获取更多帮助。

希望这可以帮助!

于 2012-05-17T11:03:54.247 回答
0
NSURL *url = [NSURL URLWithString:@"http://xyz"];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];

NSString *req;


    req = [NSString stringWithFormat:@"Name=%@&Password=%@",userName,pass];// userName and pass are string

[request setHTTPMethod:@"POST"];
[request setHTTPBody: [req dataUsingEncoding:NSISOLatin1StringEncoding]];
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
[connection start];

下面是一个代表,它将带来数据

-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData *)data
{
NSError *erro;
NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&erro];

NSLog(@"your data in dictionary is = %@",jsonData);

}

希望对你有帮助 !!!

于 2012-05-17T11:19:14.603 回答