HTTP 请求未设置内容长度
我正在尝试使用 Google Data API 在某些地方上传 CSV 文件。
我有这段代码:
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);
其中 creacionCSV 是包含所有 KML 代码的 NSString。 执行后,我从服务器获得了这个答案:
<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>
所以我收到了 411 错误。我检查了标题,它既不为零也不为空。为什么我的帖子没有采用该标头?
非常感谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何构建 tokenAutorizacion(base64 编码)?请参阅此页面: http://cocoawithlove.com/2009 /06/base64-encoding-options-on-mac-and.html
How do you build tokenAutorizacion, the base64 encoding? See this page: http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html