nsurlrequest

HTTP Status Code 411 - Length Required

梦想的初衷 提交于 2019-12-05 01:20:00
I try to get data from server. I use NSURLConnectionDelegate, NSURLConnectionDataDelegate. There is code (Objective - C). -(void)sendRequest { NSURL* url = [[NSURL alloc] initWithString:@"http://SomeServer"]; NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init]; NSString* reqBody = [NSString stringWithFormat:@"<tag>Content</tag>"]; NSData* reqData = [reqBody dataUsingEncoding:NSUTF8StringEncoding]; NSInputStream* stream = [NSInputStream inputStreamWithData:reqData]; [request setURL:url]; [request setHTTPBodyStream:stream]; [request setHTTPMethod:@"POST"]; self.wpData = [

How to download a web page with it's inner resoures like images,css in iOS?

谁都会走 提交于 2019-12-04 20:27:54
I'm trying to download the specified web pages with their inner page resources to disk. When I send a NSURLRequest, only the initial URL would be request, but the resources as images,css,js would not be download. Someone suggests to use cache, but I don't want to cache every web page browsed in the uiwebview, but only the one I specified.For example, when I input an url to the uiwebview addressbar then click on the "save" button, the page will be saved entire, but the other browsing in the webview will not be cached automatically. Does there any way to download the entire webpages? Thank you

Handling a NSURLRequest with timeout when using delegate

大城市里の小女人 提交于 2019-12-04 18:11:30
问题 I'm using a NSMutableURLRequest to connect to a web site to get a JSON response. I'm doing so by generating the request, and then using NSURLConnection with a delegate of self to handle the async connection. I've implemented all the normal delegate methods: - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error - (void)connectionDidFinishLoading:(NSURLConnection *)connection All works

NSURLRequest, why does craigslist return a 404?

微笑、不失礼 提交于 2019-12-04 17:13:48
I'm building my first iPhone app and I'm stymied. I'm trying to build an RSS reader, and I'm trying to use a feed from craigslist. This code, using stackoverflow, returns "Status code: 200": - (void)parseRSSFeed:(NSString *)feed withDelegate:(id)delegate { responseData = [[NSMutableData data] retain]; feed = @"http://stackoverflow.com"; NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:feed]]; [[NSURLConnection alloc] initWithRequest:request delegate:self]; } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSLog(@"status

Domain=NSURLErrorDomain Code=-1001 “The operation couldn’t be completed. (NSURLErrorDomain error -1001.)”

老子叫甜甜 提交于 2019-12-04 16:41:33
my program is write for upload the picture from the cam,sample code below: #define WEBSERVICE_URL @"http://192.168.0.104/upload.php" - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissViewControllerAnimated:YES completion:^{ UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage]; NSData *imageData = UIImagePNGRepresentation(selectedImage); NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:WEBSERVICE_URL parameters:nil

Returning NSDictionary from async code block? [duplicate]

白昼怎懂夜的黑 提交于 2019-12-04 14:44:33
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: returning UIImage from block Hi I'm trying to return dictionary of json twitter data so i can use it in my application. How ever it is being called from a async block. I can not save it or return it any thoughts? -(NSDictionary *)TweetFetcher { TWRequest *request = [[TWRequest alloc] initWithURL: [NSURL URLWithString: @"http://search.twitter.com/search.json? q=iOS%205&rpp=5&with_twitter_user_id=true&result_type

How to add lowercase field to NSURLRequest header field?

三世轮回 提交于 2019-12-04 13:13:40
I'm getting pretty frustrated figuring out how to add a lowercase header field to an NSMutableURLRequest. NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:MyURLString]]; [urlRequest setValue:@"aValue" forHTTPHeaderField:@"field"]; In the example above, "field" gets switched to "Field," since the header field names are case insensitive. I would think this shouldn't happen, but it does. The API I am working with is case sensitive, so my GET request is ignored. Is there any way to override the case switch? HTTP header fields are supposed to be case

How to send GEt request to PHP in iOS

馋奶兔 提交于 2019-12-04 09:01:37
问题 Hi i have problem in sending GET request to a PHP, same PHP works fine when running it in web browser here are the code snippet of both the PHP and Obj-C PHP $var1=$_GET['value1']; $var2=$_GET['value2']; when i call this in browser like http://sample.com/sample.php?value1=hi&value2=welcome it works fine, but from obj c i could't get succeed obj C NSString *url =[NSString stringWithFormat:@"http://sample.com/sample.php"]; NSData *data = [@"sample.php" dataUsingEncoding:NSUTF8StringEncoding];

How can I get NSURLResponse body?

江枫思渺然 提交于 2019-12-04 08:15:12
问题 I'm writing an application that connect with a server using NSURLConnection . In the delegate method didreceiveresponse , if the status code is 404, I cancel the connection and I would like to show a message with a custom error that is generated in the server. The problem is that from response object, I only can get statuscode, headers, mimetype, etc. but no body. How do I get the body message from NSURLResponse ? 回答1: Why do you cancel the connection? After all, 404 can have content body as

Multiple async webservice requests NSURLConnection iOS

亡梦爱人 提交于 2019-12-04 08:10:30
I have a problem that Im not sure how to tackle. I can without any problem make requests to the REST service when passing a single request. My problem now is at based on that respons i get some values including ID´s. All ID´s retrieved will then need make another request to collect new information. My guess is to load all the specific request in a array or dictionary and create request from that. Anyone have some useful tips regarding this? The information retrieved will then populate a UITableView. I suggest you use a Sync-Async Pattern on this problem. You need to implement two synchronous