Possible causes may include a bad/expired/self-signed certificate - https

I used self-signed certificate to request https buy ASIFormDataRequest, but But there may be a problem:
A connection failure occurred: SSL problem (Possible causes may include a bad/expired/self-signed certificate, clock set to wrong date)
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:url]];
[request setValidatesSecureCertificate:NO];
[request startAsynchronous];
This really solved my problem. But it did find other problems.
look the pictures:
I can see the HTTPS response clear-text, Is security?

Related

WebRequest to Shoutcast throws "invalid or unrecognized response" exception

I'm trying to read metadata from shoutcast stream using ASP.net WebAPI, .net core 2.1. All I need is the headers and not the audio data.
I found out that Shoutcast servers 2+ give stats xml page, but for compatibility reasons, I need to work this out so I can support v1 too. The /7.html does not give the title and genre.
Following is piece of relevant code:
HttpWebRequest request = null;
HttpWebResponse response = null;
request = (HttpWebRequest)WebRequest.Create(server);
request.Headers.Clear();
request.Headers.Add("GET", "/ HTTP/1.0");
// needed to receive metadata information
request.Headers.Add("Icy-MetaData", "1");
request.UserAgent = "WinampMPEG/5.09";
response = (HttpWebResponse)request.GetResponse();
info.Title=response.Headers["icy-name"];
info.Genre=response.Headers["icy-genre"];
When I run this code on IIS Express, or publish and run on IIS, I get this error:
An unhandled exception occurred while processing the request.
HttpRequestException: The server returned an invalid or unrecognized response.
System.Net.Http.HttpConnection.ThrowInvalidHttpResponse()
WebException: The server returned an invalid or unrecognized response.
System.Net.HttpWebRequest.GetResponse()
I have tried WebClient and StreamReader as well but the issue seems to be consistent.
However I tried the same code in Console Application and it seems to work just fine.
How can I get this to work through a WebAPI on IIS?
I had same issue. I used HttpClient and PostAsync to fix the issue.
It is to note that I initially tried my code with dot net framework rather than dot net core and it was working fine, so I think HttpWebResponse is not compatible with dot net core in some cases.
Have a look on below links, if using HttpClient still does not fix your issue. I hope it helps.
https://github.com/dotnet/corefx/issues/14897
https://github.com/dotnet/corefx/issues/30040

AFNetworking 2.0: NSURLSessionDownloadTask is cancelled when received 302 to AWS S3

I'm using a simple example from the README file (from AFNetworking 2.0 page) to download an image. All works fine for the images served directly from my web-sever.
But for those located on the S3 the web-server returns 302 Redirect the following error:
Error Domain=NSURLErrorDomain Code=-999 "cancelled"
When I try to download the image (using the same code) directly from the S3 (omitting the redirection) I receive the same error.
I've checked the availability of the actual image with wget. The image is publicly available (https://youguide.s3.amazonaws.com/icons/user_96x96.png).
Anyone experience the similar problem?
I was having the same problem with S3 and seem to have resolved it. AFNetworking was returning a value in the authentication challenge handling logic that was canceling the request.
By telling the AFURLSessionManager how to handle authentication challenges I've fixed the problem.
[manager setSessionDidReceiveAuthenticationChallengeBlock:^NSURLSessionAuthChallengeDisposition (NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * __autoreleasing *credential) {
return NSURLSessionAuthChallengePerformDefaultHandling;
}];

RestKit different mime type for one response

I would like to support different mime types for different responses. Most of the time the server returns json, but there are a few situations where it returns nothing and RestKit identifies these cases as plain/text mime types. Is there any solution?
I haven't tried this exactly, but it works for me when using purely AFNetworking calls. Try setting the underlying AFNetworking HTTPClient:
AFHTTPClient *client = [RKObjectManager sharedManager].HTTPClient;
[client setDefaultHeader:#"Accept" value:#"plain/text"]; // change default "Accept" header
// Put normal RestKit request code here
[client setDefaultHeader:#"Accept" value:#"application/json"]; // change back
This should work, unless RestKit is overriding the default headers somewhere. (If your request is a GET, and you don't even need RestKit's Object Mapping functionality, I suggest using the AFNetworking methods with the default client and skipping the RestKit methods in that case.)

ASIFormDataRequest Uploading file

Good Day!
i am using ASIFormDataRequest to upload file, now everthing works but the upload of file does not work. it does nothing, but other than that it works fine, i dont understand the reason, can you please help me out. here is my calling code.
[self setRequest:[ASIFormDataRequest requestWithURL:[NSURL URLWithString:#"http://localhost:8888/registerUserASI.php"]]];
[request setPostValue:strDeviceID forKey:#"userDeviceId"];
[request setPostValue:strCurrentDate forKey:#"userDateTime"];
NSData *data = UIImagePNGRepresentation(image.image);
[request setData:[[data base64Encoding] dataUsingEncoding:NSUTF8StringEncoding] forKey:#"userfile"];
btw i have also tried the SetData and AddData methods of this request as well. but same results.
The Php code is Working fine with any file upload but not this one, Can somebody help me out.
It might be php code issue that i am not properly handling for this specific request. but with other methods the uploading is working, but i want to work with this.
thanks
you say it does nothing. Did you start your request:
[request startSynchronous];
or
[request startAsynchronous];
I mostly use the async way, cause it does not freeze any UI. Then you have also to set the delegate of the request, so you also receive callbacks on success or fail of the request.
I was not converting space to its %20 just because of that it was not working.

NETWORK_ERROR: XMLHttpRequest Exception 101

I am getting this Error
NETWORK_ERROR: XMLHttpRequest Exception 101
when trying to get XML content from one site.
Here is my code:
var xmlhttp;
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
if (xmlhttp==null) {
alert ("Your browser does not support XMLHTTP!");
return;
}
xmlhttp.onReadyStateChange=function() {
if(xmlhttp.readyState==4) {
var value =xmlhttp.responseXML;
alert(value);
}
}
xmlhttp.open("GET",url,false);
xmlhttp.send();
//alert(xmlhttp.responseXML);
}
xmlhttp.open("GET",url,false);
xmlhttp.send(null);
Does any one have a solution?
If the url you provide is located externally to your server, and the server has not allowed you to send requests, you have permission problems. You cannot access data from another server with a XMLHttpRequest, without the server explicitly allowing you to do so.
Update: Realizing this is now visible as an answer on Google, I tried to find some documentation on this error. That was surprisingly hard.
This article though, has some background info and steps to resolve. Specifically, it mentions this error here:
As long as the server is configured to allow requests from your web application's origin, XMLHttpRequest will work. Otherwise, an INVALID_ACCESS_ERR exception is thrown
An interpretation of INVALID_ACCESS_ERR seems to be what we're looking at here.
To solve this, the server that receives the request, must be configured to allow the origin. This is described in more details at Mozilla.
The restriction that you cannot access data from another server with a XMLHttpRequest can apply even if the url just implies a remote server.
So:
url = "http://www.myserver.com/webpage.html"
may fail,
but:
url = "/webpage.html"
succeed - even if the request is being made from www.myserver.com
Request aborted because it was cached or previously requested? It seems the XMLHttpRequest Exception 101 error can be thrown for several reasons. I've found that it occurs when I send an XMLHttpRequest with the same URL more than one time. (Changing the URL by appending a cache defeating nonsense string to the end of the URL allows the request to be repeated. -- I wasn't intending to repeat the request, but events in the program caused it to happen and resulted in this exception).
Not returning the correct responseText or responseXML in the event of a repeated request is a bug (probably webKit).
When this exception occurred, I did get an onload event with readyState==4 and the request object state=0 and responseText=="" and responseXML==null. This was a cross domain request, which the server permits.
This was on an Android 2.3.5 system which uses webKit/533.1
Anyone have documentation on what the exception is supposed to mean?
Something like this happened with me when I returned incorrect XML (I put an attribute in the root node). In case this helps anyone.
xmlhttp.open("GET",url, true);
set the async part to true
I found a very nice article with 2 diferent solutions.
The first one implementing jQuery and JSONP, explaining how simple it is.
The second approach, it's redirecting trough a PHP call. Very simple and very nice.
http://mayten.com.ar/blog/42-ajax-cross-domain
Another modern method of solving this problem is Cross Origin Ressource Sharing.
HTML5 offers this feature. You can "wrap" your XMLhttp request in this CORS_request and
if the target browser supports this feature, you can use it and wont have no problems.
EDIT:
Additionaly i have to add that there are many reasons which can cause this Issue.
Not only a Cross Domain Restriction but also simply wrong Settings in your WEB.CONFIG of your Webservice.
Example IIS(.NET):
To enable HTTP access from external sources ( in my case a compiled Phonegap app with CORS request ) you have to add this to your WEB.CONFIG
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
Another scenario:
I got two webservices running... One on Port 80 and one on Port 90. This also gave me an XML HTTP Request Error. I even dont know why :). Nevertheless i think this can help many not well experienced readers.

Resources