(Xcode) How to connect to a PHP page?
I want to login at a page with my username and password. I want that my app connects to the php page in a UIWebView and login.
iPhone 4, iOS 4
Developer Forums relocated!
Need help with Apple Developer tools and technologies? Want to share information with other developers and Apple engineers? Visit Developer Forums at Apple.
Need help with Apple Developer tools and technologies? Want to share information with other developers and Apple engineers? Visit Developer Forums at Apple.
I want to login at a page with my username and password. I want that my app connects to the php page in a UIWebView and login.
iPhone 4, iOS 4
The people helping you get points when you mark their responses as helpful or solved (I see you have already done that). More than points to the responder, marking helps other users searching the forum for help as it lets them know which of the responses were useful to the original poster.
As long as the page you are trying to access is available on the web, the same process should work. From your perspective, you are only dealing with a HTML form handler. The handler may be implemented in any technology (PHP, Ruby, Python, .NET, Java, C/C++, PERL...)
And how do I do that? I changed the sa,e things you told me the web page and the name that the handler expects (in the source code of the page as you told me) but nothing happens
NSString *post = [[NSStringalloc] initWithFormat:@"Login=%@&password=%@",nameInput.text,passInput.text];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncodingallowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSURL *url=[NSURLURLWithString:@"http://www.info-upsite.upmx.mx/selfservice/Login.asp"];
NSMutableURLRequest *theRequest = [NSMutableURLRequestrequestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];
Look at the <form name="Login" action="xxx" in the source. You will need to specify the query string as well in your request. You can either use the URL as specified in the action or just add the parameter as part of your post body. Usually form handlers do not distinguish between URL query strings and post data.
Also, looking at the source, the username text field is named login and not Login.
Mmmm... ok! So i have to include the action of the login in my post?
Im my source it appears like this:
<form name="Login" action="Login.asp?ret_link=%2Fselfservice%2FDefault%2Easp&type=notLogged&ccsForm=Login" method="post">
login with capital L
and muy post how should it look? like this?
NSString *post = [[NSStringalloc] initWithFormat:@"Login.asp?ret_link=%2Fselfservice%2FDefault%2Easp&type=notLogged&ccsForm=Login =%@&password=%@",nameInput.text,passInput.text];
Just the parameters. No Login.asp? Are you sure you are specifying the username? You have ccsForm=Login as one parameter-value pair, so what is the name of the username parameter?
The username in sending is "0116613" but i didint understand you what do I have to change? You mean the paramters in the post?
NSString *post = [[NSStringalloc] initWithFormat:
@"No Login.asp?=%@&password=%@",nameInput.text,passInput.text];
NSString *post = [[NSStringalloc]initWithFormat:@"ccsForm=Login&login=%@&password=%@",nameInput.text,passInput.text];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncodingallowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postDatalength]];
NSURL *url=[NSURLURLWithString:@"http://www.info-upsite.upmx.mx/selfservice/Login.asp"];
NSMutableURLRequest *theRequest = [NSMutableURLRequestrequestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];
It didn't worked man! Also i don´t know what happened!! I tried to login to the php page (the one i asked you at the start) and it doesn`t works again! This is a college proyect I have to finish. Can I send you my proyect to your mail or something like that and could you check it for the two connections? I don´t know what happened.
Sorry for everything
Yes make the project available somewhere I can download from, and I can take a look.
i will upload it ti skydrive.
<iframe title ="Preview" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="width:98px;height:115px;padding:0;background-color:#fcfcfc;" src="http://cid-fc8fd5a95b070b4f.office.live.com/embedicon.aspx/.Public/UP%20%20copy. zip"></iframe>
I do not see anything really wrong with the way you are communicating with the form handler on the server (you may have to send additional parameters are part of your post body, eg. the <input type="hidden" name="xxx" value="xxx"> items).
The bigger question is what exactly do you hope to achieve with this application? Even if you successfully log in, there is not guarantee that subsequent background requests will succeed. If you want those to succeed, you will need to send over session information (cookies, session id encoded in url etc) as part of subsequent requests to the server.
I only want that the users login to tha page and they could check things of the college in those two pages (the php and the asp). But now i dont know if its correct what im and doing
Okay, there are two options for you, one that is complex (one that I have not tried, so cannot say how successful it will be), and the other that is very simple (although may not satisfy your project requirements)
1) The hard way. Get just the form post and authentication working. Once that is done, try and open the resulting HTML content in a UIWebView. This should load, but subsequent clicking on links will probably lack cookie information (that is sent as part of the response headers, which you can store and try to use later). In the web view delegate methods, attempt to inject the cookie and other header information into the request. This will work only if the request instance you are sent is a mutable instance. If not, I am afraid you are out of luck, unless your web server works in some other way that does not require cookies, and encodes the session information into each link on the page (unlikely).
2) The easy way. Create a local HTML file resouce that is designed the way you want and that will post to the form handler URL that you desire. Load this file resource in UIWebView, and everything will work as though you were using Safari.
G_Morales wrote:
But now i dont know if its correct what im and doing
I strongly suggest you issue your query (after searching there for previously related comments of course) on the iOS Dev Forums....
Ok i will try the hard way. Thaks for all your help!
Sorry the last thing i will ask you is that if you could tell me how my post should exactly be with the .asp? Please
NSString *post = [[NSStringalloc] initWithFormat:@"XXXX",nameInput.text,passInput.text];
(Xcode) How to connect to a PHP page?