Lefora Free Forum
login join
Loading
1561 views

How to return php string from server

Page 1
1–6
novice - member
27 posts


How can I retrieve a string from a php request? My requests are timing out. This is what is in the php file


<?php

return "<login attempt='Success'></login>";

?>

This is my code currently. 



- (void)attemptLoginForUser:(NSString *)username withPassword:(NSString *)password {
NSArray *keys = [NSArray arrayWithObjects:@"username", @"password", @"appID", nil];
NSArray *objects = [NSArray arrayWithObjects:username, password, @"1", nil];
NSDictionary *parameters = [NSDictionary dictionaryWithObjects:objects forKeys:keys];

NSString *url =@"https://www.mysite.com/php/loginUser.php";

BOOL firstKey=TRUE; 
for (NSString *key in parameters)
{
NSString *value=[parameters objectForKey:key];

if (firstKey) {
url=[url stringByAppendingString:@"?"];
firstKey = FALSE;
}
else {
url=[url stringByAppendingString:@"&"];
}

url=[url stringByAppendingString:key];
url=[url stringByAppendingString:@"="];
url=[url stringByAppendingString:value];
}

url=[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];

if (receivedData) {
urlConnection == nil;
receivedData == nil;
}

urlConnection = [NSURLConnection connectionWithRequest:urlRequest delegate:self];

[urlConnection start];

[self cancelToolbar];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
if (!receivedData) {
receivedData = [[NSMutableData alloc] init];
}
[receivedData appendData:data];
}


- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSXMLParser *xmlParser = [[[NSXMLParser alloc] initWithData:receivedData] autorelease];

[xmlParser setDelegate:self];
[xmlParser setShouldProcessNamespaces:NO];
[xmlParser setShouldReportNamespacePrefixes:NO];
[xmlParser setShouldResolveExternalEntities:NO];
[xmlParser parse];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[activitySpinner stopAnimating]; lb_status.text = @"Could not Login";
[self loginToolbar];
}

?
288 posts


I don't know anything about PHP and I don't seem to be able to get it to work on SL (although I've googled several tutorials of different complexity).  I think, if I've read your code correctly, in attemptLoginForUser, you're formatting a string something like:

https://blablabla/loginUser.php?username=bill&password=secret

Then, you do an HTTPS GET and you expect the sever to respond "<login .... success ....>"

I have several suggestions to help you move forward:
1) Add an NSLog(@".....").  Are you certain you are sending what you want to send?

2) Put the URL from (1) into Safari.  Does it work?

3) does this work with curl from the terminal:
$ curl https://..........?username.....
(whatever you have in your NSLog()) message from (1)

4) use my httpget program http://clanmills.com/articles/cocoatutorials/httpget.zip  enter the URL (from 1 above) and push GO.  Does it work?

I'll be happy to try this from this end if you'd like to send me the URL and a valid username and password.  You can email directly at robin@clanmills.com  I assure you I have intention to harm your web site in any way if you provide a username and password for your site.  You can checkout who I am at clanmills.com




__________________
novice - member
27 posts

1. check
2. check
3. This is the output I get: [1] 23117
4. nothing happens

I am not actually preforming any username validation, I am returning the string <login ...../> as a response for any request of that url.

?
288 posts

I wonder if this has something to do with the https ?  Is it possible to try options (1) .. (4) on an http port?

Can you send me a url that I can try from this end.  I know your website isn't actually called mywebsite.com.

Can you do:
$ curl --verbose https://blabla
and send me the output. 

__________________
novice - member
27 posts

I tried http and got the same hanging, I actually meant to type http and not https.


* About to connect() to blabla port 443 (#0)
*   Trying 67.63.55.3... Operation timed out
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host

?
288 posts

Port 443 is https.  If curl can't connect, I think it's unlikely that NSURLConnection will be able to connect either.  So, how does Safari manage to do this.  Ummmmmmm.

We need to resolve the communications before it's worth examining the Cocoa code.  I have a C++ http client (which I wrote myself).  It's cross platform and runs on MacOSX (and Windows and Linux).  So I can go debug down to the socket connections if necessary.  

Is it possible for me to try this from here (in California)?  Of may I send you the C++ code and you can try with that.

__________________
Page 1
1–6

Locked Topic


You must be a member to post in this forum

Join Now!