안녕하세요 저는 Silverlight에서 웹 사이트로 일부 데이터를 게시하고 싶습니다.
다음과 같은 것을 발견했습니다 link ...
그러나 ....이 예제는 너무 정교해서 내 눈을 다 치게 만들었습니다.
또한 .. 플렉스 예 .. 우리는 훨씬 청소기/적은 코드 .. 참고로
내가 더 나은 솔루션이 있어야합니다라고 말하고 싶지만 ...Silverlight HTTP POST 몇 가지 변수, 간단한 예제 (최소 코드)
2 개 변수 (문자열)를 게시하고 읽은 out 결과 (문자열).
링크에서 솔루션 :
1. // C#
2. // Create a request object
3. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(POST_ADDRESS, UriKind.Absolute));
4. request.Method = "POST";
5. // don't miss out this
6. request.ContentType = "application/x-www-form-urlencoded";
7. request.BeginGetRequestStream(new AsyncCallback(RequestReady), request);
8.
9. // Sumbit the Post Data
10. void RequestReady(IAsyncResult asyncResult)
11. {
12. HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest;
13. Stream stream = request.EndGetRequestStream(asyncResult);
14.
15. // Hack for solving multi-threading problem
16. // I think this is a bug
17. this.Dispatcher.BeginInvoke(delegate()
18. {
19. // Send the post variables
20. StreamWriter writer = new StreamWriter(stream);
21. writer.WriteLine("key1=value1");
22. writer.WriteLine("key2=value2");
23. writer.Flush();
24. writer.Close();
25.
26. request.BeginGetResponse(new AsyncCallback(ResponseReady), request);
27. });
28. }
29.
30. // Get the Result
31. void ResponseReady(IAsyncResult asyncResult)
32. {
33. HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest;
34. HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);
35.
36. this.Dispatcher.BeginInvoke(delegate()
37. {
38. Stream responseStream = response.GetResponseStream();
39. StreamReader reader = new StreamReader(responseStream);
40. // get the result text
41. string result = reader.ReadToEnd();
42. });
43. }
이것은 훨씬 나아 보입니다. 나는 그것을 시험해 볼 것이다. .. –