title: How to send html request to a service url
body: <p>How can I send html request from iPhone to <code>service url</code>.Can I take the whole html data in string and pass the <code>string variable</code> as one of <code>xml tag and POST request</code>?Do I need any conversions.</p>
  
  <p>My html request is like this </p>
  
  <pre><code>&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;&amp;#xD;
          &amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;&amp;#xD;
          &amp;lt;head&amp;gt;&amp;#xD;
          &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&amp;gt;&amp;#xD;
          &amp;lt;title&amp;gt;Untitled Document&amp;lt;/title&amp;gt;&amp;#xD;
          &amp;lt;/head&amp;gt;&amp;#xD;
          &amp;#xD;
          &amp;lt;body style="background:#bdd9ef; padding:20px 0px; margin:0px;"&amp;gt;&amp;#xD;
              &amp;lt;table width="700px" cellspacing="0" cellpadding="0" style="border-radius:10px; margin:0px auto; background:white; color:#2222; padding:20px 0px;" &amp;gt;&amp;#xD;
          &amp;#xD;
  ................
  ................
  </code></pre>
  
  <p>I m doing it in the following way :</p>
  
  <pre><code> 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:@"&lt;EmailServiceRequest xmlns=\"http://schemas.datacontract.org/2004/07/\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"&gt;"]dataUsingEncoding:NSUTF8StringEncoding]];
           [postBody appendData:[[NSString stringWithFormat:@"&lt;HtmlBody&gt;%@&lt;/HtmlBody&gt;",htmldata]dataUsingEncoding:NSUTF8StringEncoding]];
            [postBody appendData:[[NSString stringWithFormat:@"&lt;/EmailServiceRequest&gt;"]dataUsingEncoding:NSUTF8StringEncoding]];
          [request setHTTPBody:postBody];
          NSHTTPURLResponse *urlResponse=nil;
          NSError *error=nil;
          NSData *responseData = [NSURLConnection sendSynchronousRequest:request
                                                        returningResponse:&amp;urlResponse
                                                                    error:&amp;error];
  
          if (responseData!= NULL)
          {
              NSString *rss = [[NSString alloc] initWithData:responseData
                                                     encoding:NSUTF8StringEncoding ];
              NSLog(@"Response Code:%d",[urlResponse statusCode]);
              if([urlResponse statusCode ]&gt;=200 &amp;&amp; [urlResponse statusCode]&lt;300)
              {
                  NSLog(@"Response:%@",rss);
              }
          }
          else
          {
              NSLog(@"Failed to send request: %@", [error localizedDescription]);
          }
  </code></pre>
  
  <p>But I m getting error and unable to POST</p>
  
  <p>Any suggestions/help would be highly appreciable </p>