使用objective-c执行PHP脚本 [英] Executing a PHP script using objective-c

查看:79
本文介绍了使用objective-c执行PHP脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行一个PHP脚本,该脚本会增加数据库中的字段。我有脚本工作,我目前正在使用ASIHTTPRequest完美地修改数据库,但我觉得我应该使用不同的方法,因为我不需要返回。



<这是什么叫做HTTP POST?

  incrementOrDecrementURL = [[NSString alloc] initWithFormat:@http:// myURL /doScript.php]; 

NSURL * requestURL = [[NSURL alloc] initWithString:incrementOrDecrementURL];

//实际请求
ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL:requestURL];
//成为请求委托
//获取requestFinished:或requestFailed等回调:
[request setDelegate:self];

//开始请求
[request startAsynchronous];


解决方案

形成 docs:使用ASIFormDataRequest发送表单POST

  ASIFormDataRequest * request = [ASIFormDataRequest requestWithURL:url]; 
[请求setPostValue:@BenforKey:@first_name];
[请求setPostValue:@CopseyforKey:@last_name];
[request setFile:@/ Users / ben / Desktop / ben.jpgforKey:@photo];

但请注意,ASIHTTPRequest不是由其原始作者维护。


I'm trying to execute a PHP script which increments a field in a database. I have the script working and I am currently modifying the database perfectly using ASIHTTPRequest, but I feel as though I should be using a different method given that I do not need a return.

Is this what's called an HTTP POST?

    incrementOrDecrementURL = [[NSString alloc] initWithFormat:@"http://myURL/doScript.php"];

NSURL *requestURL = [[NSURL alloc] initWithString:incrementOrDecrementURL];

//The actual request
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:requestURL];
// Becoming the request delegate
//To get callbacks like requestFinished: or requestFailed:
[request setDelegate:self];    

// Start request
[request startAsynchronous]; 

解决方案

form the docs: Sending a form POST with ASIFormDataRequest

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"Ben" forKey:@"first_name"];
[request setPostValue:@"Copsey" forKey:@"last_name"];
[request setFile:@"/Users/ben/Desktop/ben.jpg" forKey:@"photo"];

But also note, that ASIHTTPRequest is not maintained anymore by it's original author.

这篇关于使用objective-c执行PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆