Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone-HTTPPOST:向web xml发送值_Iphone_Objective C_Xcode_Http Post - Fatal编程技术网

iPhone-HTTPPOST:向web xml发送值

iPhone-HTTPPOST:向web xml发送值,iphone,objective-c,xcode,http-post,Iphone,Objective C,Xcode,Http Post,我知道这方面有很多问题,但似乎没有一个对我想做的事情起作用。我想更改标记的值,假设我有以下文件: </Courbe> <tempset>140</tempset> </Courbe> 140 我希望http post请求更改此值。我该怎么做 我已经尝试过类似的方法: - (IBAction)changeTemp:(id)sender { NSMutableURLRequest *request = [[NSMutableURLRequest

我知道这方面有很多问题,但似乎没有一个对我想做的事情起作用。我想更改标记的值,假设我有以下文件:

</Courbe>
<tempset>140</tempset>
</Courbe>

140
我希望http post请求更改此值。我该怎么做

我已经尝试过类似的方法:

- (IBAction)changeTemp:(id)sender 
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL     URLWithString:@"http://207.134.145.16:50001/Courbe.xml"]];
[request setHTTPMethod:@"POST"];
[request setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];

NSString *xmlString = @"<tempset>137</tempset>";

[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
-(iAction)changeTemp:(id)发送方
{
NSMutableURLRequest*请求=[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:@]http://207.134.145.16:50001/Courbe.xml"]];
[请求设置HttpMethod:@“POST”];
[请求设置值:@“文本/xml”用于HttpHeaderField:@“内容类型”];
NSString*xmlString=@“137”;
[[NSURLConnection alloc]initWithRequest:请求委托:self];
}

是这样的吗?谢谢你的帮助

Url对XML字符串进行编码,然后:

NSData *postData = [xmlString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[request setHTTPBody:postData];
[request setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
要发送,请使用以下内容:

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {}];
在iOS5之前,您可以通过以下方式异步发送:

// make the request and an NSURLConnection with a delegate
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];

// create a property to hold the response data, then implement the delegate methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response  {
    responseData = [[NSMutableData alloc] init];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    [responseData release];
    [textView setString:@"Unable to fetch data"];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString *responseString = [[[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding] autorelease];
}

您是否已调用
-start
+sendSynchronousRequest:returningResponse:error:
?(见)不,因为这是一个按钮,也许我应该编辑它。但是我不必正确地调用它?上面的代码只创建了一个连接对象,但没有开始请求/响应事务。因此,如果我使用这个[[NSURLConnection alloc]initWithRequest:request delegate:self StartImmediate:YES];它应该启动吗?是
+initWithRequest:delegate:startimmediate:
也将启动。阅读
NSURLConnection
的整个章节。您需要设置适当的
nsurlconnectionelegate
方法。这可能很好,但我忘了提到我正在开发4.0 my bad+1以供尝试!thanks@BenLefebvre,看来你问题的出发点是如何设置帖子的主体。这在我回答中的前几行代码中得到了演示。如何发送请求是另一个问题。我将编辑我的答案以包含IOS尝试几次后,我可以让请求正常工作..但我不知道如何更新xml文件中的值。因此,如果我理解:文件是远程的,您有本地副本?您读取本地副本,通过http发布更改,然后想要更新本地副本。我有这个权利吗?这可能是一个新的问题。你能问一下并贴一个链接吗?(顺便说一句,如果我的问题正确并且文件很小,我的第一个想法是让web服务回答修改后的文件。您可以替换您的本地副本。否则,编写xml有一些客户端解决方案。让我们