如何将 html 请求从 iPhone 发送到service url
。我可以将整个 html 数据放入字符串中并string variable
作为其中之一传递xml tag and POST request
吗?我需要任何转换吗?
我的html请求是这样的
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body style="background:#bdd9ef; padding:20px 0px; margin:0px;">
<table width="700px" cellspacing="0" cellpadding="0" style="border-radius:10px; margin:0px auto; background:white; color:#2222; padding:20px 0px;" >

................
................
我正在通过以下方式进行操作:
NSString *url=[NSString stringWithFormat:@"http://XXX/services/Email.svc"];
NSMutableURLRequest *request=[[[NSMutableURLRequest alloc] init]autorelease];
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];
NSString *contentType=[NSString stringWithFormat:@"text/xml"];
[request addValue:contentType5 forHTTPHeaderField:@"Content-Type"];
NSMutableData *postBody=[NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:@"<EmailServiceRequest xmlns=\"http://schemas.datacontract.org/2004/07/\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">"]dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"<HtmlBody>%@</HtmlBody>",htmldata]dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"</EmailServiceRequest>"]dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postBody];
NSHTTPURLResponse *urlResponse=nil;
NSError *error=nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request
returningResponse:&urlResponse
error:&error];
if (responseData!= NULL)
{
NSString *rss = [[NSString alloc] initWithData:responseData
encoding:NSUTF8StringEncoding ];
NSLog(@"Response Code:%d",[urlResponse statusCode]);
if([urlResponse statusCode ]>=200 && [urlResponse statusCode]<300)
{
NSLog(@"Response:%@",rss);
}
}
else
{
NSLog(@"Failed to send request: %@", [error localizedDescription]);
}
但我收到错误并且无法发布
任何建议/帮助都将不胜感激