Silverlight 2.0 official version cross-domain submit data full Raiders

Source: Internet
Author: User

Note The code for this article is based on the Silverlight 2.0 official edition.

Silverlight 2.0 official release, there have been some changes in the HttpWebRequest, the previous code in the official version may not be able to run the specific

The main changes are:

1, the Request stream must be closed before calling Httpwebrequest.begingetresponse ();

Exception thrown by 2,httpwebrequest.endgetresponse (), before the official version, Httpwebrequest.beinggetresponse (), cross domain, cross protocol access to throw security exception, all other requests return 404 error, Now, the error of Httprequest.endgetresponse () is thrown as an exception, a security-related error is thrown SecurityException, and a unsuccessful request throws a WebException exception. Webexception.response is set to Httpstatuscode.notfound.

Because HttpWebRequest sends asynchronous requests, if you want to interact with the interface, it also involves thread synchronization, which reports "invalid cross-thread access" errors if you do not synchronize threads. The following is a practical example of submitting data to a Java Servlet address, returning the submitted data to the current interface. Of course, there's no problem submitting to the ASPX page, just add the following code to the Page_Load event-handling method:

protected void Page_Load(object sender, EventArgs e)
{
 if (Request.RequestType.Equals("POST"))
 {
  Response.ClearContent();
   Response.ClearHeaders();
  Response.Write("您提交的数据是:" + Request.Params.Get ("data"));
  Response.End();
  return;
 }
}

If you submit to the Java Servlet, the test code can write:

public void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
  response.getWriter().print("您提交的数据是:" + request.getParameter("data"));
}

To perform cross-domain testing on this computer, you need to set up in the Hosts file, such as:

127.0.0.1 www.mengxianhui.com

127.0.0.1 www.xianhuimeng.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.