开发者

HTTP Request does not set Content Length

开发者 https://www.devze.com 2023-04-07 11:38 出处:网络
I\'m trying to use Google Data API to upload a CSV file with some places. I\'ve this piece of code: NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:direc

I'm trying to use Google Data API to upload a CSV file with some places.

I've this piece of code:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:direccion]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:direccion]];

NSData *postData = [creacionCSV dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"2.0" forHTTPHeaderField:@"GData-Version"];
[request setValue:@"application/vnd.google-earth.kml+xml" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"Mapa de prueba" forHTTPHeaderField:@"Slug"];
[request setHTTPBody:postData];
[request setHTTPMethod:@"POST"];

NSData *datosRecibidos;
datosRecibidos = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *token = [[NSString alloc] initWithData:datosRecibidos encoding:NSASCIIStringEncoding];
NSLog(开发者_高级运维@"%@",token);

Where creacionCSV is an NSString with all the KML code. Once executed, I've obtained this answe from server:

<html lang=en>
  <meta charset=utf-8>
  <title>Error 411 (Length Required)!!1</title>
  <style> [...] </style>
  <a href=//www.google.com/ id=g><img src=//www.google.com/images/logo_sm.gif alt=Google></a>
  <p><b>411.</b> <ins>That’s an error.</ins>
  <p>POST requests require a <code>Content-length</code> header.  
  <ins>That’s all we know.</ins>

So I'm getting that 411 Error. I've checked the header and it's not nil nor empty. Why is not taking that header my POST?

Many thanks!


How do you build tokenAutorizacion, the base64 encoding? See this page: http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html

0

精彩评论

暂无评论...
验证码 换一张
取 消