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#的
解决方案 »
- 能不能实现用linkbutton实现和hyperlink一样的连接效果(页面自动打开,文件自动下载),点击连接存储下载记录信息?
- (诚信高分求)从ASP.NET + SQL 2005 转到 ASP.NET + SQL 2000 出现了这样的错误
- 在调试数据库中一个事务处理例子时遇到的问题........
- ASP.NET2.0网站中动态加载用户控件时点两下的问题
- 怎么用C#将服务器上的word(图和文字)读出来显示成网页的内容。
- 未能加载类型
- 同志们:asp.net怎么知道DataGrid总共有多少页呢?
- ♂一个JS拖拽文本复制的问题,万分感谢!
- asp.net(c#)中字符转换-----急急
- 如何使得页面在提交表单后自动关闭?
- C#解析XML
- 关于usercontrol属性的问题
/// 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();
}
加上验证就prefect了