脚本宝典收集整理的这篇文章主要介绍了在PHP中,iPhone POST请求始终被$_SERVER [‘REQUEST_METHOD’]视为GET,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我的POST请求如下(通过Wireshark嗅探):
POST tester.PHP HTTP/1.1 Host: localhost User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0.2) Gecko/20100101 Firefox/10.0.2 Accept: text/htML,application/xhtml+XMl,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Connection: keep-alive Referer: http://localhost/tester.PHP Content-tyPE: application/x-www-form-urlencoded Content-Length: 422 PRotocol=4&msgtype=authorize&merchant=86189919&language=da&ordernumber=1274168351&amount=100¤cy=DKK&continueurl=http%3A%2F%2Fquickpay.net%2Ffeatures%2Fpayment-window%2Fok.PHP&cancelurl=http%3A%2F%2Fquickpay.net%2Ffeatures%2Fpayment-window%2Ferror.PHP&callbackurl=http%3A%2F%2Fquickpay.net%2Ffeatures%2Fpayment-window%2fcallback.PHP&autocapture=0&cardtypelock=&splITpayment=1&md5check=d2259d9db077e0f5a41b4bf271c3c549
当然,那里有很多虚拟文本,通常不会出现在iPhone上,但是我试图通过html表单进行相同的调用,这很有效.因此,我已经复制了所有信息,看看这是否有所作为,但无济于事.
我比较了两个请求(一个来自iPhone,另一个来自我的PHP页面),它们看起来完全一样.
我大吃一惊 – 有没有人对如何做有很好的建议?
编辑:
是的,这可能是真的,但该行总是返回GET,因此案例问题已经涵盖,如果这就是你的意思.
数组(HTTP_HOST => 10.11.105.254 HTTP_USER_AGENT => Mozilla / 5.0(iPhone模拟器; cpu iPhone OS 5_1,如Mac OS X)Applewebkit / 534.46(KHTML,如Gecko)mobile / 9B176 HTTP_ACCEPT => text / html,应用程序/ xhtml xml,application / xml; q = 0.9,/; q = 0.8 HTTP_ACCEPT_LANGUAGE => en-us HTTP_ACCEPT_ENCODING => gzip,deflate HTTP_CONNECTION => keep-alive PATH => /usr/bin:/ bin: /usr/sbin:/ sbin SERVER_SIGNATURE => apache / 2.2.21(Unix)DAV / 2 PHP / 5.3.8与Suhosin-Patch Server在10.11.105.254端口80
SERVER_Software => Apache / 2.2.21(Unix)DAV / 2 PHP / 5.3.8与Suhosin-Patch SERVER_NAME => 10.11.105.254 SERVER_ADDR => 10.11.105.254 SERVER_PORT => 80 REMOTE_ADDR => 10.11.105.254 DOCUMENT_ROOT => / Library / WebServer / Documents SERVER_ADMIN => you@example.COM SCRIPT_FILENAME => /Users/tester.PHP REMOTE_PORT => 51492 GATEWAY_INTERFACE => CGI / 1.1 SERVER_PROTOCOL => HTTP / 1.1 REQUEST_METHOD => GET QUERY_STRING => REQUEST_URI => /tester.PHP SCRIPT_NAME => /tester.PHP PHP_SELF => /tester.PHP REQUEST_TIME => 1334211212 argv => Array argc => 0)
当我尝试从iPhone请求中回显已知变量时,它当然是空的.这是有道理的.当我从表格中回应同样的东西时就在那里.
以下是创建请求并发送请求的代码:
//VARiables NSString *protocol = @"4"; NSString *msgtype = @"authorize"; NSString *merchant = @"86189919"; NSString *language = @"da"; NSString *orderNo = @"1274168351"; NSString *amount = @"100"; NSString *currency = @"DKK"; NSString *continueURL = @"http://quickpay.net/features/payment-window/ok.PHP"; NSString *cancelURL = @"http://quickpay.net/features/payment-window/error.PHP"; NSString *callbackURL = @"http://quickpay.net/features/payment-window/callback.PHP"; NSString *autoCapture = @"0"; NSString *cardtypeLock =@""; NSString *splitText = @"1"; NSString *md5check = @"d2259d9db077e0f5a41b4bf271c3c549"; //setting up the request NSMutableString *post = [[NSMutableString alloc] initWithString:@"protocol="]; [post appendString:protocol]; [post appendString:@"&msgtype="]; [post appendString:msgtype]; [post appendString:@"&merchant="]; [post appendString:merchant]; [post appendString:@"&language="]; [post appendString:language]; [post appendString:@"&ordernumber="]; [post appendString:orderNo]; [post appendString:@"&amount="]; [post appendString:amount]; [post appendString:@"¤cy="]; [post appendString:currency]; [post appendString:@"&continueurl="]; [post appendString:continueURL]; [post appendString:@"&cancelurl="]; [post appendString:cancelURL]; [post appendString:@"&callbackurl="]; [post appendString:callbackURL]; [post appendString:@"&autocapture="]; [post appendString:autoCapture]; [post appendString:@"&cardtypelock="]; [post appendString:cardtypeLock]; [post appendString:@"&splitpayment="]; [post appendString:splitText]; [post appendString:@"&md5check="]; [post appendString:md5check]; //escape characters NSString *tmp = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes( NULL,(__bridge CFStringRef)post,NULL,(CFStringRef)@";/:@+$,~",kcfStringEncodingUTF8 ); NSData *body = [tmp dataUsingEncoding:NSUTF8StringEncoding]; //SETUP url NSString *urlString =@"http://10.10.225.255/tester.PHP"; NSURL *quickUrl = [NSURL URLWithString:urlString]; //setup URL request NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init]; //method [request setHTTPMethod:@"POST"]; //url [request setURL:url]; //body data to string NSString *strData = [[NSString alloc]initWithData:body encoding:NSUTF8StringEncoding]; //content length NSString *postLenght = [NSString stringWithFormat:@"%d",[body length]]; //set body [request setHTTPBody:body]; //Dummy data to make the request look like the same From the HTML form. [request setValue:@"localhost" forHTTPHeaderField:@"Host"]; [request setValue:@"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0.2) Gecko/20100101 Firefox/10.0.2" forHTTPHeaderField:@"User-Agent"]; [request setValue:@"text/html,*/*;q=0.8" forHTTPHeaderField:@"Accept"]; [request setValue:@"en-us,en;q=0.5" forHTTPHeaderField:@"Accept-Language"]; [request setValue:@"gzip,deflate" forHTTPHeaderField:@"Accept-Encoding"]; [request setValue:@"http://localhost/tester.PHP" forHTTPHeaderField:@"Referer"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"]; [request setValue:postLenght forHTTPHeaderField:@"content-length"]; //send the request to server if([[NSURLConnection alloc] initWithrequest:request delegate:self]){ NSLOG(@"sending data to quickpay"); }
以上是脚本宝典为你收集整理的在PHP中,iPhone POST请求始终被$_SERVER [‘REQUEST_METHOD’]视为GET全部内容,希望文章能够帮你解决在PHP中,iPhone POST请求始终被$_SERVER [‘REQUEST_METHOD’]视为GET所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。