title: Translate a Web Service POST from Java to .NET
body: <p>Below is a snipped from a Java Client that connects to a website and uploads a file via the POST method.  I have to reproduce this client in a Visual Studio environment, but I don't see any equivalent functions in the .NET environment for the <a href="http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/methods/HttpEntityEnclosingRequestBase.html#setEntity%28org.apache.http.HttpEntity%29" rel="nofollow">setEntity()</a> function used in the Java.  </p>
  
  <p>Everything I've found points to using this...</p>
  
  <pre><code>public void uploadFile(File uploadFile, String partner, String key,
              String baseUrl,boolean isPartner) throws IOException {
      DefaultHttpClient httpclient = new DefaultHttpClient();
      httpclient.getParams().setParameter(
          CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1
      );
      String url = baseUrl + "?" + (isPartner ? "partnerId" : "ori") + "="
              + partner.toUpperCase() + "&amp;authKey=" 
              + key+ "&amp;key=" 
              + key;
      HttpPost httppost = new HttpPost(url);
      MultipartEntity multipartEntity = new MultipartEntity();
      ContentBody contentBody = new FileBody(uploadFile, "text/xml"); 
      multipartEntity.addPart("dataFile", contentBody); 
      httppost.setEntity(multipartEntity);
  
      HttpResponse response;
      response = httpclient.execute(httppost);
  
      HttpEntity resEntity = response.getEntity();
  
      if (resEntity != null) {
          resEntity.consumeContent();
      }
  
      httpclient.getConnectionManager().shutdown();
  }
  </code></pre>
  
  <p>Everything I've found in Visual studio uses something like this below for the POST method.  The <a href="http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx" rel="nofollow">WebRequest</a> object has no obvious way of adding the parameters I need.   </p>
  
  <pre><code>Dim request As WebRequest = WebRequest.Create("http://Test.com/import?partnerId=2&amp;authKey=XdUa")
  request.Method = "POST"
  Dim postData As String = StrData
  Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
  request.ContentType = "dataStr"
  request.ContentLength = byteArray.Length
  Dim dataStream As Stream = request.GetRequestStream()
  dataStream.Write(byteArray, 0, byteArray.Length)
  dataStream.Close()
  Dim response As WebResponse = request.GetResponse()
  </code></pre>
  
  <p>Any guidance would be greatly appreciated.  If my question is not clear, let me know, I'll try again.</p>