nsurlrequest

iOS any body knows how to add a proxy to NSURLRequest?

旧巷老猫 提交于 2019-11-30 01:00:34
I'm setting up a webview but I need to load the content of the webview using a proxy. Any of you knows how can I'm implement the proxy in NSURLRequest? for example: NSString *location=@"http://google.com"; NSURL *url=[NSURL URLWithString:location]; NSURLRequest *request=[NSURLRequest requestWithURL:url]; // some code to set the proxy [self.myWebView loadRequest:request]; I'll really appreciate your help Take a look at iOS URL Loading System as well as NSURLProtocol You can write a custom NSURLProtocol class for your NSURLRequest. A custom NSURLProtocol can intercept your requests and add proxy

Swift 2.0, Alamofire: Set cookies in HTTP Post Request

不羁的心 提交于 2019-11-29 18:24:37
问题 I want to set cookies in my HTTP POST request. Something like the cookie field in the HTTP Request below, version: 0.1.7 Cookie: client=Android; version=0.1.7; sellerId=SEL5483318784; key=178a0506-0639-4659-9495-67e5dffa42de Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Content-Length: 1431 How can I achieve this with Alamofire? My current Alamofire request is like this, Alamofire.request(.POST, ServerConfig.ADD_PRODUCT_URL, parameters: productJSON, encoding: .JSON, headers:

converting image to base64 and uploading in JSON format to server

女生的网名这么多〃 提交于 2019-11-29 16:48:06
I have a problem. I need to convert base64 string to JSON string and pass it to server. for example I have a base64 string /9j/4AAQSkZJRgABAQAAAQABAAD/4QBYRXhpZgAATU0AKgAAAAgAAgESAAMAAAABAAEAAIdpAAQAAAABAAAAJgAAAAAAA6ABAAMAAAABAAEAAKACAAQAAAABAAAACqADAAQAAAABAAAACgAAAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/Z i need to convert it to JSON format. I do the following: +(NSData *)prepareForUploading:(NSString *)base64Str { NSDictionary *dict=[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:base64str, nil] forKeys:[NSArray

NSMutableURLRequest timeout doesn't trigger if data starts to load but not webViewDidFinishLoad

旧时模样 提交于 2019-11-29 15:53:48
I am loading a UIWebview and requesting a URL that can take some time to finish loading. The request starts and begins to receive data. However, it doesn't appear that the request finishes. The webViewDidFinishLoad never triggers nor does the webView didFailLoadWithError: callback. Does a timeout of a NSURLRequest only occur if there is no response receiving data or does it trigger if the request doesn't complete in that interval as well? If it's the former, is there an elegant solution to timing out the request? Relevant code is: Load the request: - (void) loadRequest { NSString *targetURL =

“No Action header was found” error message while using SOAP webservice

删除回忆录丶 提交于 2019-11-29 14:33:09
问题 Getting following error while consuming SOAP webservice in iOS App "No Action header was found with namespace 'http://www.w3.org/2005/08/addressing' for the given message." The same webservice working fine in SOAP UI Tool. Following is the request format NSString *data = @"<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tem=\"http://tempuri.org/\"> <soap:Header></soap:Header> <soap:Body><tem:GetEvaluators></tem:GetEvaluators></soap:Body> </soap:Envelope>"; NSString

Change User-Agent

杀马特。学长 韩版系。学妹 提交于 2019-11-29 12:42:41
How can I change in my WebView the default string of User-Agent? @IBOutlet weak var myWbView: UIWebView! let myURL = NSURL(string: "http://http://web-example") let myURLRequest:NSURLRequest = NSURLRequest(URL: myURL!) myWbView.loadRequest(myURLRequest) Alexander Tkachenko If you want to set User-Agent HTTP header for your request that is going to be used for Web-view loading, let userAgent = "Custom User Agent"; let myURL = NSURL(string: "http://http://web-example") let myURLRequest:NSURLRequest = NSMutableURLRequest(URL: myURL!) myWbView.loadRequest(myURLRequest) myURLRequest.setValue

iOS: Is it possible to open NSURLRequest directly in Safari?

房东的猫 提交于 2019-11-29 07:25:11
I'm not talking about a UIWebView , I want to open the mobile safari app using an NSURLRequest . Why? In my app, the user has already logged into our web server. I want to give the user the option of launching the webpage without having to reenter their credentials. However, I can't use a GET because that would put their credentials in the URL. So, can I open the safari app (not a UIWebView ) from my app with an NSURLRequest or a POST in some other form? MrGomez I'm going to put my neck on the line and say no — there's no way to pass an NSURLRequest directly to Safari. The (primary) inter

Alternative method for NSURLRequest's private “setAllowsAnyHTTPSCertificate:forHost:”?

大城市里の小女人 提交于 2019-11-29 06:21:33
问题 My iPhone application was rejected solely for using the (very safe, it seems) private method +setAllowsAnyHTTPSCertificate:forHost: for NSURLRequest. Is there a non-private API to emulate this functionality? 回答1: There seems to be a public API for that ;) How to use NSURLConnection to connect with SSL for an untrusted cert? 回答2: Actually, I'm testing with 10.6.8 and this code still works -- it's using the private API but checking that the selector exists (myurl is the NSURL I'm trying to load

Cache for WKWebView

元气小坏坏 提交于 2019-11-29 06:10:52
I am having trouble with my custom internet browser. I am using WKWebView. I have tabs in my app. If I click on a tab new NSURLRequest loads in the WKWebView. I need to implement a cache. If a user presses on a tab, I'd prefer to load a cache data instead of new. Unfortunately this code doesn't work: NSURLRequest *request = [[NSURLRequest alloc] initWithURL:URL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:0.0]; [self.webView loadRequest:request]; Can you guide me on how to implement cache for WKWebView? If you used NSURLRequestUseProtocolCachePolicy , which is the default,

Get cookies from NSHTTPURLResponse

流过昼夜 提交于 2019-11-29 04:16:49
I've an extremely weird problem, I'm requesting a URL and I want to get the cookies from it, I've used this way to get the cookies: - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response; NSDictionary *fields = [HTTPResponse allHeaderFields]; NSString *cookie = [fields valueForKey:"Set-Cookie"]; } BUT the cookies is not complete, there is some field is missing, I've checked it on PostMan, all the cookies is there. I've used also this method when initiating the NSURLRequest . [request