Monday, March 26, 2012
System.Net HttpWebRequest - post a form
From: senthil t
There is a third party website that we use=2E Whenever someone=
unsubscribes from our website, some one has to go to that third=
party website, enter the unsubscribed user info and submit the=
form=2E We are doing this manually=2E What I would like is, whenever=
any user unsubscribes from our website, auto post the third=
party website form with all the user information from my =2Enet=
code=2E This is the code I have right now=2E But this is not=
working=2E
HttpWebRequest webRequest =3D (HttpWebRequest) WebRequest=2ECreate=
(URL);
webRequest=2EKeepAlive =3D false;
webRequest=2ETimeout =3D 100000;
webRequest=2EMethod =3D "POST";
webRequest=2EContentType =3D "application/x-www-form-urlencoded";
byte[] requestBytes =3D (new=
System=2EText=2EASCIIEncoding())=2EGetBy
tes (PostData);
webRequest=2EContentLength =3D requestBytes=2ELength;
Stream requestStream =3D webRequest=2EGetRequestStream();
requestStream=2EWrite (requestBytes, 0, requestBytes=2ELength);
requestStream=2EClose();
webResponse =3D (HttpWebResponse) webRequest=2EGetResponse();
sr =3D new StreamReader (webResponse=2EGetResponseStream(),=
System=2EText=2EEncoding=2EASCII);
response =3D sr=2EReadToEnd ();
With =2Easpx page, it was not doing anything until I added the=
viewstate info to the postdata=2E But is throwing an error at this=
line=2E
webResponse =3D (HttpWebResponse) webRequest=2EGetResponse();
Internal Server Error=2ESystem=2ENet=2EHttpWebResponse at=
System=2ENet=2EHttpWebRequest=2ECheckFin
alStatus() at=
System=2ENet=2EHttpWebRequest=2EEndGetRe
sponse(IAsyncResult=
asyncResult) at System=2ENet=2EHttpWebRequest=2EGetRespo
nse()
Can any one tell me what is wrong with what I am doing?
Posted by a user from =2ENET 247 (http://www=2Edotnet247=2Ecom/)
<Id>0ZTNUiUrPECOfo+INVokdg=3D=3D</Id>Hi senthil:
What I've done in the past is use a tool like Fiddler [1] to compare
what my program is POSTing to the server versus what happens when I
use a browser.
http://www.fiddlertool.com/fiddler/
Scott
http://www.OdeToCode.com/blogs/scott/
On Sun, 15 May 2005 05:03:55 -0700, senthil t via .NET 247
<anonymous@.dotnet247.com> wrote:
>(Type your message here)
>--
>From: senthil t
>There is a third party website that we use. Whenever someone unsubscribes from our
website, some one has to go to that third party website, enter the unsubscribed user
info and submit the form. We are doing this manually. What I would like is, wheneve
r a
ny user unsubscribes from our website, auto post the third party website form with all the
user information from my .net code. This is the code I have right now. But this is not work
ing.
> HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create (URL);
> webRequest.KeepAlive = false;
> webRequest.Timeout = 100000;
> webRequest.Method = "POST";
> webRequest.ContentType = "application/x-www-form-urlencoded";
> byte[] requestBytes = (new System.Text.ASCIIEncoding()).GetBytes (PostDa
ta);
> webRequest.ContentLength = requestBytes.Length;
> Stream requestStream = webRequest.GetRequestStream();
> requestStream.Write (requestBytes, 0, requestBytes.Length);
> requestStream.Close();
> webResponse = (HttpWebResponse) webRequest.GetResponse();
> sr = new StreamReader (webResponse.GetResponseStream(), System.Text.Enco
ding.ASCII);
> response = sr.ReadToEnd ();
>With .aspx page, it was not doing anything until I added the viewstate info
to the postdata. But is throwing an error at this line.
>webResponse = (HttpWebResponse) webRequest.GetResponse();
>Internal Server Error.System.Net.HttpWebResponse at System.Net.HttpWebReque
st.CheckFinalStatus() at System.Net.HttpWebRequest.EndGetResponse(IAsyncResu
lt asyncResult) at System.Net.HttpWebRequest.GetResponse()
>Can any one tell me what is wrong with what I am doing?
>--
>Posted by a user from .NET 247 (http://www.dotnet247.com/)
><Id>0ZTNUiUrPECOfo+INVokdg==</Id>
Tuesday, March 13, 2012
System.Resources.MissingManifestResourceException: How to edit .resources file
Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure "Menu.resources" was correctly embedded or linked into assembly "SkyMenu". baseName: Menu locationInfo: skmMenu.Menu resource file name: Menu.resources assembly: SkyMenu, Version=2.2.2078.30514, Culture=neutral, PublicKeyToken=null
Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details:System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure "Menu.resources" was correctly embedded or linked into assembly "SkyMenu". baseName: Menu locationInfo: skmMenu.Menu resource file name: Menu.resources assembly: SkyMenu, Version=2.2.2078.30514, Culture=neutral, PublicKeyToken=null
Source Error:
|
NC...
No Luck. Still getting same error.
Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure "Menu.resources" was correctly embedded or linked into assembly "SkyMenu". baseName: Menu locationInfo: skmMenu.Menu resource file name: Menu.resources assembly: SkyMenu, Version=2.2.2081.16098, Culture=neutral, PublicKeyToken=null
System.Security.SecurityException: That assembly does not allow partially trusted callers.
I developed a web site using .net 2.0, mysql 4.0 and IIS 5.0. The server is hosted by a third party.
I am using the MySql.Data.dll library version 5.0.7.0 to connect to the database. I did not create any custom assembly and I am using the MySqlData objects directly from the code:
using MySql.Data.MySqlClient;
MySqlConnection conn;
MySqlDataAdapter data_retriever;
DataTable TextDataTable;
TextDataTable = new DataTable();
data_retriever = new MySqlDataAdapter(last_query_executed.Value.ToString(), conn);
data_retriever.Fill(TextDataTable);
This is the error I get:
System.Security.SecurityException: That assembly does not allow partially trusted callers.
[SecurityException: That assembly does not allow partially trusted callers.]
search_search.BindData() +0
search_search.Page_Load(Object sender, EventArgs e) +30
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6978
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +213
System.Web.UI.Page.ProcessRequest() +86
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +18
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.search_search_aspx.ProcessRequest(HttpContext context) +4
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +303
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64
My level of knowledge of .NET and Visual Studio is not advanced.
Do you have any suggestions?
Thanks,
Christian
Here is a post on the issue. It seems the current server configuration does not allow partial trusted callers.
http://bloggingabout.net/blogs/rick/archive/2006/04/07/11929.aspx -- this may not really apply becaus eyour site is hosted by a 3rd party
http://forums.mysql.com/read.php?38,95478,96748#msg-96748 -- has a link to download a new version of MySql assembly allowing partial trust. Not sure it will work, mixed results
http://forums.asp.net/t/999456.aspx -- has some other solutions. One of which is using a ODBC connection to MySql instead.
http://dev.mysql.com/tech-resources/articles/dotnet/ --see for ODBC driver details
I tried to recompile the library. However, I get a compilation error after I add the following line in the Assemplyinfo.cs:
[assembly: AllowPartialllyTrustedCallers]
Any ideas?
Christian
What error did you get? Also post your AssemblyInfo.cs file.
I fixed this problem, I was missing the following line:
using
System.Security;
however, now i am getting the error:
Unable to connect to any of the specified MySQL hosts.