简体   繁体   中英

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

So I have this url that leads to a .php

So far I managed to retrieve every single thing except the actual XML that I want. the XML is stored in a variable called _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.

- (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.

- (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. 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

My question is, how do I get back that xml variable? Isn't there a method available within the ASIHTTPRequest library? I am using ASIFormDataRequest class not ASIHTTPRequest.

You have to print you variable in the php-file:

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. It only returns the string you actually print.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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