『壹』 各位高手,做C#web時報了個這么個錯誤,下面是詳細錯誤,Load方法根本就沒走,何來未將對象實例化呢
錯誤原因告訴你了:未將對象引用設置到對象的實例。
你肯定是頁面中用到了一個對象,但是這個對象沒有實例化!
『貳』 編譯器錯誤消息: CS0117: 「System.Web.HttpPostedFile」並不包含「ContentLegth」的定義
位元組[] [] _PIC =新的位元組[6] [];
/ /嘗試
/ /(
為(廉政檔案= 0;文件「Request.Files.Count;文件+ +)
(
HttpPostedFile newfile = Request.Files [檔案];
廉政imageSize = newfile.ContentLength;
_PIC [檔案] =新的位元組[imageSize];
廉政數= newfile.InputStream.Read(_PIC [文件],0,imageSize);
_PIC [檔案] = newfile.GenerateThumbImg(_PIC [文件],630,420);
)
/ /)
『叄』 CS0118: 「System.Web.HttpRequest.Params」是「屬性」,但此處被當做「方法」來使用
這是一個FxCop警告,他的意思是Request.Params是一個屬性,而不是一個方法,應該用屬性的方式進行調用,也就是改為Request.Params["name"]。
這個問題的來源在於C#對索引器的處理,索引器可以使用xxxx["yyyy"]的方式進行調用,也可以被當作一個次級方法使用xxxx("yyyy")的方式來進行調用。為了保護程序的可讀性和編譯器性能,微軟建議使用索引器的方式而不是方法的方式來進行訪問。
『肆』 C# httprequest,webrequest,有什麼區別
System.Web.HttpRequest是封裝瀏覽器對伺服器的請求的,主要用在ASP.NET中,其中包括瀏覽器請求的網址,查詢字元串數據或表單數據等等
而System.Net.HttpWebRequest則是用來簡化網路請求的過程,從伺服器上獲取文件/結果的,譬如你可以在代碼中用這個類冒充瀏覽器(設置一個UserAgent)來發請求,處理回應
第一:他們不是父子關系。
第二:Syste.Net.HttpWebRequest 類是System.Net.WebRequest抽象類的一個子類,它是 .NET Framework 的用於訪問 Internet 數據的請求/響應模型的抽象基類。使用該請求/響應模型的應用程序可以用協議不可知的方式從 Internet 請求數據。在這種方式下,應用程序處理 WebRequest 類的實例,而協議特定的子類則執行請求的具體細節。
System.Net.HttpWebRequest 類和System.Net.FileWebRequest都繼承了WebRequest
1、FileWebRequest 類為使用 file:// 方案來請求本地文件的 URI 實現 WebRequest 抽象基類。
2、HttpWebRequest 類對 WebRequest 中定義的屬性和方法提供支持,也對使用戶能夠直接與使用 HTTP 的伺服器交互的附加屬性和方法提供支持。
第三:System.Web.HttpRequest 類使 ASP.NET 能夠讀取客戶端在 Web 請求期間發送的 HTTP 值。HttpRequest 類的方法和屬性通過 HttpApplication、HttpContext、Page 和 UserControl 類的 Request 屬性公開。
所以使用System.Web.HttpRequest類的時候其實都是利用HttpApplication、HttpContext、Page 和 UserControl 類的 Request 屬性。而使用System.Net.HttpWebRequest類時是為了獲得一個Uri資源。自己創建。
System.Web 命名空間提供使得可以進行瀏覽器與伺服器通信的類和介面。此命名空間包括 HttpRequest 類(用於提供有關當前 HTTP 請求的廣泛信息)、HttpResponse 類(用於管理對客戶端的 HTTP 輸出)以及 HttpServerUtility 類(用於提供對伺服器端實用工具與進程的訪問)。System.Web 還包括用於 Cookie 操作、文件傳輸、異常信息和輸出緩存控制的類。
System.Net 命名空間為當前網路上使用的多種協議提供了簡單的編程介面。WebRequest 和 WebResponse 類形成了所謂的可插接式協議的基礎,可插接式協議是網路服務的一種實現,它使您能夠開發出使用 Internet 資源的應用程序,而不必考慮各種不同協議的具體細節。
【3】核心區別
System.Web.HttpRequest:Incoming,進入請求,也就是客戶端訪問ASP.NET 網站進入時的請求。所以只能在ASP.NET應用程序上下文里使用。
System.Net.HttpWebRequest:OutGoing,外發請求,可以發出一個HTTP請求,它可以乾的活,就比較多了,可以模擬一個獨立的客戶端,向網站發送請求。
『伍』 怎麼升級system.web.http
檢查一下你的Bin文件夾下有沒有System.Web.Http.WebHost.dll文件,如果有,請檢查dll的版本。將System.Web.Http.WebHost.dll 4.0版本的文件放入到Bin文件夾下,基本就能解決此問題了! 但是有可能會提醒其他未能載入文件或者程序集錯誤,請檢查...
『陸』 引發類型為「System.Web.HttpUnhandledException」的異常。
原因:當你參數不存在時,Request.QueryString("OutlineID")為NULL值,這個時候你怎麼能把它toString()呢,在空值上操作肯定是要報你空引用的錯誤的!!
解決方法:Request.QueryString("OutlineID")可直接做字元串使用,不需要toString()就可以了!
『柒』 c# HttpWebResponse判斷返回請求的問題
沒明白你什麼意思給你一個我測試的代碼吧
HttpReceiveData.aspx
///
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HttpReceiveData.aspx.cs" Inherits="HttpReceiveData" %>
HttpReceiveData.aspx.cs
///////
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class HttpReceiveData : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.Write("nihao" + Request.Form["Desc"] + Request.Form["Title"]);
Response.End();
////string c = Request.Form["nihao"].ToString();
//String a = Request.Form["Title"].ToString();
//String b = Request.Form["Desc"].ToString();
//Common d = new Common();
//d.ShowMessage(this, a + b);
}
}
HttpSendData.aspx
//
<%@ Page language="c#" %>
<%@ Import Namespace = "System" %>
<%@ Import Namespace = "System.Collections" %>
<%@ Import Namespace = "System.Web" %>
<%@ Import Namespace = "System.Web.UI" %>
<%@ Import Namespace = "System.Web.UI.WebControls" %>
<%@ Import Namespace = "System.Net" %>
<%@ Import Namespace = "System.IO" %>
<%@ Import Namespace = "System.Text" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<script type="text/C#" runat="server">
void Button1_Click(object sender, System.EventArgs e)
{
string strTitle = TextBox1.Text;
string strDesc = TextBox2.Text;
//Encoding encoding = Encoding.GetEncoding("GB2312");
//string postData = "Title=" + strTitle;
//string strUrl = "http://localhost/ht/HttpReceiveData.aspx";
//postData += ("&Desc=" + strDesc);
//byte[] data = encoding.GetBytes(postData);
//// 准備請求...
//HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);
//myRequest.Method = "POST";
//myRequest.ContentType="application/x-www-form-urlencoded";
//myRequest.ContentLength = data.Length;
//Stream newStream=myRequest.GetRequestStream();
//// 發送數據
//newStream.Write(data,0,data.Length);
//newStream.Close();
CookieContainer cc = new CookieContainer();
string postData = "Title=" + strTitle;
//string strUrl = "http://localhost/ht/HttpReceiveData.aspx";
postData += ("&Desc=" + strDesc);
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 轉化
HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create("http://localhost/ht/HttpReceiveData.aspx");
webRequest2.CookieContainer = cc;
webRequest2.Method = "POST";
webRequest2.ContentType = "application/x-www-form-urlencoded";
webRequest2.ContentLength = byteArray.Length;
Stream newStream = webRequest2.GetRequestStream();
// Send the data.
newStream.Write(byteArray, 0, byteArray.Length); //寫入參數
newStream.Close();
HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
long t = response2.ContentLength;
StreamReader sr2 = new StreamReader(response2.GetResponseStream(), Encoding.Default);
string text2 = sr2.ReadToEnd();
Response.Redirect("HttpSendData.aspx");
}
</script>
</HEAD>
<body>
<form id="HTTPPost" method="post" runat="server">
標題:<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<br>
內容:
<br>
<asp:TextBox id="TextBox2" runat="server" TextMode="MultiLine" Rows="10" Columns="100"></asp:TextBox>
<br>
<asp:Button id="Button1" runat="server" Text=" 發 送 " onclick="Button1_Click"></asp:Button>
</form>
</body>
</HTML>
HttpSendData.aspx文件
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class HttpSendData : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
『捌』 請教C++中怎麼使用HttpWebRequest
給你舉個例子
C/C++ code
std::string getHTML()
{
System::String^ HTML;
try
{
System::Net::HttpWebRequest^ request = (System::Net::HttpWebRequest^)System::Net::WebRequest::Create("http://blog.csdn.net/rrrfff");
request->Proxy = nullptr;
System::Net::HttpWebResponse^ response = (System::Net::HttpWebResponse^)request->GetResponse();
{
System::IO::StreamReader^ reader = gcnew System::IO::StreamReader(response->GetResponseStream());
{
HTML = reader->ReadToEnd();
}
reader->Close();
}
response->Close();
}
catch (System::Exception^ ex)
{
//ex->Message;
}
return marshal_as<std::string>(HTML);
}
『玖』 C#winForm 怎麼調用System.Web.HttpCookie類
cookie是只有在http通訊中才涉及到的協議,在winform中根本沒有它適用的環境
『拾』 未能載入文件或程序集System.Web.Http或它的某一個依賴項.找到的程序集清單定義與程序集引用不匹配。
請問 解決了嗎?我也出現了這種情況 怎麼解決了?