public class Testing {
private static String HOST="192.168.0.46";
private static String URL="/Windchill/rfa/jsp/gateway.jsp";
private static String GEATWAY_URL="http://192.168.0.46:8008/Windchill/rfa/jsp/gateway.jsp";
private static String USERNAME="wcadmin";
private static String PASSWORD="wcadmin";
public static void main(String[] args) {
try { DefaultHttpClient httpclient = new DefaultHttpClient();
        
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(HOST, 8008),
new UsernamePasswordCredentials(USERNAME, PASSWORD)); HttpPost httppost = new HttpPost(GEATWAY_URL);
httppost.setHeader("Content-type","text/xml;charset=utf-8");
String xmlRequestData= "<flexplmdephi to=\"server\" name=\"create\"><createinfo><datatype>supplierRequest</datatype><datalist><supplierRequest><name>EP_SUPPLIER12</name><EPAfullName>12supplier from Jiaxing</EPAfullName><EPAsupplierID></EPAsupplierID><EPAtype></EPAtype><EPAaddress>Beijin Road</EPAaddress><EPAbank>Shenzhen development bank</EPAbank><EPAtaxCode>12taxCode2888</EPAtaxCode><EPAaccount>123456789</EPAaccount><EPAstatus></EPAstatus><EPAcontants.EPAcontantsName>Jason Zhang</EPAcontants.EPAcontantsName><EPAcontants.EPAemail>[email protected]</EPAcontants.EPAemail><EPAcontants.EPAphone>0721-8888888</EPAcontants.EPAphone></supplierRequest></datalist></createinfo></flexplmdephi>";
//xmlRequestData="<flexplmdephi to=\"server\" name=\"query\"><queryinfo><datatype>supplier</datatype><supplier><supplierName>wcadmin</supplierName></supplier></queryinfo></flexplmdephi>";
StringEntity sendEntity = new StringEntity(xmlRequestData.toString());
httppost.setEntity(sendEntity); System.out.println(">>EP start executing request:" + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity();
System.out.println("-------get the status line---start--------");
System.out.println(response.getStatusLine());
System.out.println("-------get the status line--end------------");
String phrase = response.getStatusLine().getReasonPhrase();
System.out.println("--Response phrase="+phrase);
int statusCode = response.getStatusLine().getStatusCode();
if (entity != null) {
System.out.println("Response content length: "+ entity.getContentLength());
}
if (statusCode == 200) {
System.out.println("-------------Read The Response InputStream----------------");
InputStream input = response.getEntity().getContent();
SAXReader readers = new SAXReader(); Document document = readers.read(input);
System.out.println(document.getRootElement().asXML().replaceAll(">", ">\r\n\t"));
}
if (entity != null) {
entity.consumeContent();
}

httpclient.getConnectionManager().shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
}
翻译成C#的

解决方案 »

  1.   

    参照这个方法, 翻译?/// <summary>
            /// POST方式
            /// </summary>
            /// <param name="strURL">URI资源</param>
            /// <param name="strParm">POST参数</param>
            /// <param name="timeOut">超时值:以毫秒为单位</param>
            /// <returns></returns>
            public static string HttpPost(string strURL, string strParm, int timeOut)
            {
                StringBuilder rStr = new StringBuilder();
                try
                {
                    byte[] postBytes = Encoding.GetEncoding("GB2312").GetBytes(strParm);                // byte[] postBytes = Encoding.ASCII.GetBytes(UrlEncodeGB2312(strParm));
                    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(strURL);
                    request.Timeout = timeOut;
                    request.Method = "POST";
                    request.ContentType = "text/xml";  //"application/x-www-form-urlencoded";                 request.ContentLength = postBytes.Length;
                    Stream requestStream = request.GetRequestStream();
                    requestStream.Write(postBytes, 0, postBytes.Length);
                    requestStream.Close();
                    HttpWebResponse response = null;
                    try
                    {
                        response = (HttpWebResponse)request.GetResponse();
                    }
                    catch (WebException e)
                    {
                        response = (HttpWebResponse)e.Response;
                    }
                    Stream responseStream = response.GetResponseStream();
                    StreamReader streamReader = new StreamReader(responseStream, Encoding.Default);
                    while (streamReader.Peek() != -1)
                    {
                        rStr.Append(streamReader.ReadLine());
                    }
                    streamReader.Close();
                    response.Close();
                }
                catch { }
                return rStr.ToString();
            }
      

  2.   

    楼上ok。
    加上验证就prefect了