0
代碼如下,當我擊中的頁面:任何想法爲什麼這個ASP.NET C#代碼發送http請求不起作用?
它與加載條慢慢移動,直到永遠我阻止它只是有點掛,我也不曾忘記做一些事情?我找不出哪一行代碼實際上用來「提交」請求...
注意:用戶名/密碼和[公司名稱]是共享代碼的佔位符,並在我的運行中包含正確的值代碼
using System;
using System.Web;
using System.Xml;
using System.Net;
using System.IO;
public class bctimepost : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
string project_id = context.Request.QueryString["project"];
string person_id = context.Request.QueryString["person"];
string post_date = context.Request.QueryString["date"];
string post_hours = context.Request.QueryString["hours"];
string case_num = context.Request.QueryString["case"];
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create("https://[company name].updatelog.com/projects/" + project_id + "/time_entries.xml");
objRequest.Method = "POST";
objRequest.ContentType = "application/xml";
objRequest.Accept = "application/xml";
string creds = "username:password";
byte[] encData_byte = new byte[creds.Length];
encData_byte = System.Text.Encoding.UTF8.GetBytes(creds);
string encodedData = Convert.ToBase64String(encData_byte);
objRequest.Headers.Add("Authorization", "Basic " + encodedData);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = (" ");
using (XmlWriter writer = XmlWriter.Create(objRequest.GetRequestStream(), settings))
{
writer.WriteStartElement("time-entry");
writer.WriteElementString("person-id", person_id);
writer.WriteElementString("date", post_date);
writer.WriteElementString("hours", post_hours);
writer.WriteElementString("description", "Worked on Case #" + case_num);
writer.WriteEndElement();
}
HttpWebResponse myHttpWebResponse = (HttpWebResponse)objRequest.GetResponse();
context.Response.Write(myHttpWebResponse.StatusCode);
}
public bool IsReusable {
get {
return false;
}
}
}
哦,你是SOOO男人 – BigOmega 2009-04-17 19:48:06