日期:2014-05-18  浏览次数:20869 次

请问一个HTTP的PUT方法程序的异常,谢谢!
请问大家,写了个方法,在main里调用了该函数。异常已经标出,不知道有几种原因?会不会uri错了?拜谢!

C# code
 public static string ModifiyFixedCost(CookieContainer cookieContainer)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://10.63.11.34/vCenter-CB/api/hierarchy/696/entity/697/costModel/701/fixedCosts/values");
            request.CookieContainer = cookieContainer;
            request.Method = "PUT";
            request.KeepAlive = true;
            request.Timeout = 600000;
            request.ContentType = "application/x-www-form-urlencoded";//application/x-www-form-urlencoded
            Stream streamReq = request.GetRequestStream();

            ///Read XML file.
            String strXML;
            string strCurrentPath = System.IO.Directory.GetCurrentDirectory();
            string strPath;
            strPath = strCurrentPath + "\\ModifiyFixedCostXML.txt";

            using (StreamReader sr = new StreamReader(strPath))
            {
                strXML = sr.ReadToEnd();
            }

            string strResp;
            byte[] byteArray = Encoding.UTF8.GetBytes(strXML);
            streamReq.Write(byteArray, 0, byteArray.Length);
            streamReq.Close();

            using (WebResponse response = request.GetResponse())
            //报异常:WebException was unhandled: The remote server returned an error:(500)Internal Server Error.
            //Trace:   at System.Net.HttpWebRequest.GetResponse()
                       at ChargeBack.ChargeBack.ModifiyFixedCost(CookieContainer cookieContainer) in C:\Users\Administrator\documents\visual studio 2010\Projects\ChargeBack\ChargeBack\ChargeBack.cs:line 340
                       at ChargeBack.ChargeBack.Main(String[] args) in C:\Users\Administrator\documents\visual studio 2010\Projects\ChargeBack\ChargeBack\ChargeBack.cs:line 86
                       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
                       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
                       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
                       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
                       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
                       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
                       at System.Threading.ThreadHelper.ThreadStart()
            {
                Stream streamResp = response.GetResponseStream();
                StreamReader streamReaderResp = new StreamReader(streamResp);
                strResp = streamReaderResp.ReadToEnd();
            }
            return strResp;
        }


------解决方案--------------------
你服务器支持PUT方法么
------解决方案--------------------
WebException was unhandled: The remote server returned an error:(500)Internal Server Error.

500的错误应该是对方服务器处理时出错了,直接网页访问可以吗?
.Net4需要显示关闭代理Proxy