简体   繁体   English

ASIFormDataRequest-iOS应用程序。 如何检索帖子变量

[英]ASIFormDataRequest - iOS Application. How do I RETRIEVE a post variable

So I have this url that leads to a .php 所以我有这个网址,导致一个.php

So far I managed to retrieve every single thing except the actual XML that I want. 到目前为止,我设法检索了除我想要的实际XML之外的所有东西。 the XML is stored in a variable called _xml. XML存储在名为_xml的变量中。

if($this->outMethod=="" || $this->outMethod=="POST") //Default to POST
{
$_POST["_xml"] = $_xml; 
}

So I've already set the outMethod to POST but I don't understand how to retrieve the value within _xml. 因此,我已经将outMethod设置为POST,但是我不了解如何在_xml中检索值。

- (void)grabURLInBackground
{
NSLog(@"grab url in background");
NSURL *url = [NSURL URLWithString:@"xxxxxxxxxxx"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"POST" forKey:@"outMethod"];
[request setPostValue:@"1" forKey:@"Entity_ID"];
[request setDelegate:self];
[request startAsynchronous];
NSLog(@"end of grabUrlInBackgroun");
}

don't worry the URL is right I just don't want to post it. 不用担心URL是正确的,我只是不想发布它。

- (void)requestFinished:(ASIHTTPRequest *)request
{
NSLog(@"A");
// Use when fetching text data
NSString *responseString = [request responseString];

// Use when fetching binary data
NSData *responseData = [request responseData];

if(responseString)
{
NSLog(@"responseData is not null");
}

NSLog(@"response string: %@", responseString);

//NSLog(@"%@", responseString);
}

What I get back is that the request is good, but there is no response in responseString. 我得到的是请求很好,但是responseString中没有响应。 This is because my php does not want to print out any of the XML on screen in HTML but it stores the result in the variable _xml sent via post "$_POST["_xml"] = $_xml 这是因为我的php不想在HTML屏幕上打印出任何XML,而是将结果存储在通过帖子“ $ _POST [” _ xml“] = $ _xml发送的变量_xml中

My question is, how do I get back that xml variable? 我的问题是,如何获取该xml变量? Isn't there a method available within the ASIHTTPRequest library? ASIHTTPRequest库中没有可用的方法吗? I am using ASIFormDataRequest class not ASIHTTPRequest. 我正在使用ASIFormDataRequest类而不是ASIHTTPRequest。

You have to print you variable in the php-file: 您必须在php文件中打印变量:

if($this->outMethod=="" || $this->outMethod=="POST") //Default to POST
{
    echo $_xml; 
}

A HTTPRequest (and the ASIFormDataRequest as well) isn't interested in any variables you declare in your *.php file. HTTPRequest(以及ASIFormDataRequest也)对您在* .php文件中声明的任何变量都不感兴趣。 It only returns the string you actually print. 它仅返回您实际打印的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM