Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode WebView未传递POST参数_Xcode_Macos_Webview_Httprequest - Fatal编程技术网

Xcode WebView未传递POST参数

Xcode WebView未传递POST参数,xcode,macos,webview,httprequest,Xcode,Macos,Webview,Httprequest,我需要将一些post参数传递给服务器,但是php得到了一个空数组 美元邮政 这是我的代码: NSString* user=UserNameField.stringValue; NSString* pass=PasswordField.stringValue; NSString* ID=IDField.stringValue; NSURL *url = [NSURL URLWithString:ENTERANCE]; url = [NSURL URLWithString:@"http://sp

我需要将一些post参数传递给服务器,但是php得到了一个空数组 美元邮政 这是我的代码:

 NSString* user=UserNameField.stringValue;
NSString* pass=PasswordField.stringValue;
NSString* ID=IDField.stringValue;

NSURL *url = [NSURL URLWithString:ENTERANCE];
url = [NSURL URLWithString:@"http://sphere-beauty.com/test.php"];


NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString* post=[NSString stringWithFormat:@"uname=%@&passwd=%@&id=%@",user,pass,ID];

[req setHTTPMethod:@"POST"];
[req setHTTPBody: [post dataUsingEncoding:NSUTF8StringEncoding]];



[[browser mainFrame] loadRequest:req];
有人能帮忙吗

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"www.aaa.com"]];
[request setHTTPMethod:@"POST"];
NSString *request_body = [NSString stringWithFormat:@"u=aaa&p=aaa"];
[request setHTTPBody:[request_body dataUsingEncoding:NSASCIIStringEncoding]];
NSError *error;
NSURLResponse *response;
NSData *theData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
这就是我通常以同步方式与服务器通信的方式


这就是我通常以同步方式与服务器通信的方式…

这段代码对我来说很有用,向测试页面发送一个简单的POST请求

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *name=@"Freddy Krueger!";
    NSString *encodedName = [name urlencode];
    NSString *postString = [NSString stringWithFormat:@"name=%@", encodedName];
    NSData *data = [postString dataUsingEncoding:NSASCIIStringEncoding];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://192.168.1.100/www/posttest.php"]];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:data];

    [web loadRequest:request];

    // Non-ARC
    // [request release];
}
[name urlencode]
调用
NSString*
上的
urlencode
类别方法,该方法位于以下位置:

web
显然是我的
UIWebView


您的代码可能会失败,因为您没有对参数进行URL编码。

此代码适用于我,向测试页面发送一个简单的POST请求

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *name=@"Freddy Krueger!";
    NSString *encodedName = [name urlencode];
    NSString *postString = [NSString stringWithFormat:@"name=%@", encodedName];
    NSData *data = [postString dataUsingEncoding:NSASCIIStringEncoding];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://192.168.1.100/www/posttest.php"]];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:data];

    [web loadRequest:request];

    // Non-ARC
    // [request release];
}
[name urlencode]
调用
NSString*
上的
urlencode
类别方法,该方法位于以下位置:

web
显然是我的
UIWebView


您的代码可能会失败,因为您没有对参数进行URL编码。

设置URL然后覆盖它有什么意义?这仅用于测试,查看post数据设置URL然后覆盖它有什么意义?这仅用于测试,查看post数据