response not coming with initWithContentsOfURL - iphone

I have an url i am executing,
The encoded url is like,
http://admin:testsite#www.arabcircleonline.com/index.php?do=%2Fwebservice%2Fwhisper%2Flogin_chauhankevalp%40gmail.com%2Fpassword_keval%2Faction_whisper%2Fwhisperdata_%7B%22user_status%22%3A%22test123%22%2C%22privacy%22%3A0%2C%22privacy_comment%22%3A0%7D
When i execute it with NSURLConnection or initWithContentsOfURL both are not giving the response expected.
how this should be executed?
This url is protected with username and password.. is there any concern with this?.. I am using the authentication to make the URL work on server
Help will be appreciated..

Related

How can I access the redirected url in postman?

I have a big problem. I'm sending a request on postman. Then, the url is redirected. I can see the redirected url in Postman console. But I can't access it from the test tab. I need to access the redirected url because the token is generated here. I can do the same operation using the regular expression extractor in JMeter. But I can't do it in Postman. How can I do this in postman? Can you help me?
enter image description here
You can turn off redirects on a specific request (toggle Automatically follow redirects):
Then you can access the Location header contents through:
pm.response.headers.get('Location')
Following that, you can hit the redirect URL via sendRequest or saving the URL in a Postman variable and using setNextRequest.

NSURLConnection delegate methods not giving the response immediately

Hi in my application I am using NSURLConnection delegate metods to get a response from the server.Here what is happening is when ever I send a request to the server for the first time I am getting response immediately.After that first request if I send same request to the server again immediately I am getting the response as null. But if i leave the ipad aside after sometime I am getting the response can you please let me know is there any time limit needed between the requests while sending to the server using NSURLConnection delegate methods.Please help me to resolve this issue.
Thanks in advance.

AFNetworking - does its HTTP request send with cookies by default?

I am trying to debug a http get request i sent via AFNetworking's AFJSONRequestOperation to see if the cookies are being sent correctly. However, i dont see any cookies in http header. Can some expert help me out here? thanks! :)
You can set the cookie to your AFHTTPClient or it's subclass with the following line
[_httpClient setDefaultHeader:#"Cookie" value:#"cookie=value"];
I've tried this with my server and it works. It can clearly catch the cookie named cookie and it's related value.

Synchronous request or asynchronous when checking user's login data

In my application i need to implement verification if user has entered correct login and password or not. the login and the password are stored at the web server so i have to organize correct connection to the server. I'm an absolute beginner in everything about http requests and all that stuff. Actually i downloaded ASIHTTPRequest library and added it to my project just yesterday. My main problem is that i don't have an actual server by now (and i' m using just a conventional URL which later will be replaced with true server name but i want my code to be correct already)so i cannot test myself whether i'm doing things correctly or not.So my questions are:
1)What is the best way to organize verifying user's login and password? Should i use synchronous request or asynchronous? For all i know synchronous requests are rare in use cause they stop the application while the request is being performed but there's really nothing else needed to be done in this event so i'm a bit confused.What would you use?
2)I suppose verifying user's login and password by using http requests is pretty common task so there must be a general rule what kind of data the web server returns. I don't want to invent a wheel. should i use NSString returned by responseString to check if user's login and password match? What does server returns usually in such cases? How should my code look like? Something like
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:someUrl];
[request startSynchronous];
NSString *response = [request responseString];
if ([response isEqualToString:#"login and password match"])
//user enters next screen
else
//user is notified about the error
or something else? What would you do?
3)This request is not only i need to implement. Later i'm going to connect to the same URL with a different request. So how does the server know what kind of request is currently being used?
I really need your advice. Great thanks in advance
I have tried to answer your question,
Q:1. Synchronous or Asynchronous request model for login?
-> As per apple's documentation
A synchronous load is built on top of the asynchronous loading code made
available by the class. The calling thread is blocked while the asynchronous
loading system performs the URL load on a thread spawned specifically for
this load request.
also,
NSURLConnection provides support for downloading the contents of an
NSURLRequest in a synchronous manner using the class method
sendSynchronousRequest:returningResponse:error:. Using this method is
not recommended, because it has severe limitations:
The client application blocks until the data has been completely
received, an error is encountered, or the request times out.
Minimal support is provided for requests that require authentication.
There is no means of modifying the default behavior of response
caching or accepting server redirects.
As you are unaware of server side implementation, which may involve:
1. Redirection and other mechanisms for fulfilling the request.
2. It may require some proxy authentication or other similar stuff.
Q:2. What does server returns usually in such cases?
In general, a web service is implemented at server-side which returns XML or JSON as repsonse which you have to parse and use.
example response may look like:
for XML:
<auth>
<statusCode>0</statusCode>
<statusMessage>Login Successful.</statusMessage>
</auth>
for JSON
{
"statusCode" = "0"
"statusMessage" = "Login Successful."
}
tags(for XML) and keys(for JSON) will depend upon you sever implementation.
3. How does the server know what kind of request is currently being used?
-> The URL which you will use for request will tell server, what you are looking for?
for example
http://www.example.com/mywebapp/getItem?id="1";
Thanks,
or
http://www.example.com/mywebapp/removeItem?id="1";
The bold path item represents services which you are calling.

UIWebView Unsupported URL

I'm using a UIWebView that's using an offline HTML file to manage it's workflow.
But, every time I tap on one of the items in the UIWebView the workflow is correct but I get a console message telling me that the URL is invalid.
The message is as follows:
{
NSErrorFailingURLKey = "applewebdata://BA77B31A-D9ED-4883-84BB-4270BCBEECA5?selected#node-2866424";
NSErrorFailingURLStringKey = "applewebdata://BA77B31A-D9ED-4883-84BB-4270BCBEECA5?selected#node-2866424";
NSLocalizedDescription = "unsupported URL";
NSUnderlyingError = "Error Domain=kCFErrorDomainCFNetwork Code=-1002 \"unsupported URL\" UserInfo=0x592ece0 {NSErrorFailingURLKey=applewebdata://BA77B31A-D9ED-4883-84BB-4270BCBEECA5?selected#node-2866424, NSErrorFailingURLStringKey=applewebdata://BA77B31A-D9ED-4883-84BB-4270BCBEECA5?selected#node-2866424, NSLocalizedDescription=unsupported URL}";
}
The error is quite clear, but I'm not completely sure where the error comes from, seeing that my URL is correct via the URI standard, as far as I know.
"applewebdata://BA77B31A-D9ED-4883-84BB-4270BCBEECA5?selected#node-2866424"
I don't know if there are differences between a normal HTTP URL and an AppleWebData URL, but this is correct according to the URI scheme.
e.g.:
scheme name:file name:query:fragment
Am I missing something here? I'd like to have my UIWebView do it's work without complaining about an incorrect URL, because the workflow is good. It does what I intended, but just not without being quiet.
Thanks in advance!
Bryan
Assuming you are loading this with loadHTMLString:, try setting the page's baseUrl as mentioned in this question: shouldStartLoadWithRequest appending link with applewebdata