WP8 C# 如何post数据并获取返回值

WP8 C# 如何post数据并获取返回值,第1张

接收:

public partial class Post_Server : SystemWebUIPage

{

protected void Page_Load(object sender, EventArgs e)

{

string type = "";

string Re = "";

Re += "数据传送方式:";

if (RequestRequestTypeToUpper() == "POST")

{

type = "POST";

Re += type + "<br/>参数分别是:<br/>";

SortedList table = Param();

if (table != null)

{

foreach (DictionaryEntry De in table) { Re += "参数名:" + DeKey + " 值:" + DeValue + "<br/>"; }

}

else

{ Re = "你没有传递任何参数过来!"; }

}

else

{

type = "GET";

Re += type + "<br/>参数分别是:<br/>";

NameValueCollection nvc = GETInput();

if (nvcCount != 0)

{

for (int i = 0; i < nvcCount; i++) { Re += "参数名:" + nvcGetKey(i) + " 值:" + nvcGetValues(i)[0] + "<br/>"; }

}

else

{ Re = "你没有传递任何参数过来!"; }

}

ResponseWrite(Re);

}

//获取GET返回来的数据

private NameValueCollection GETInput()

{ return RequestQueryString; }

// 获取POST返回来的数据

private string PostInput()

{

try

{

SystemIOStream s = RequestInputStream;

int count = 0;

byte[] buffer = new byte[1024];

StringBuilder builder = new StringBuilder();

while ((count = sRead(buffer, 0, 1024)) > 0)

{

builderAppend(EncodingUTF8GetString(buffer, 0, count));

}

sFlush();

sClose();

sDispose();

return builderToString();

}

catch (Exception ex)

{ throw ex; }

}

private SortedList Param()

{

string POSTStr = PostInput();

SortedList SortList = new SortedList();

int index = POSTStrIndexOf("&");

string[] Arr = { };

if (index != -1) //参数传递不只一项

{

Arr = POSTStrSplit('&');

for (int i = 0; i < ArrLength; i++)

{

int equalindex = Arr[i]IndexOf('=');

string paramN = Arr[i]Substring(0, equalindex);

string paramV = Arr[i]Substring(equalindex + 1);

if (!SortListContainsKey(paramN)) //避免用户传递相同参数

{ SortListAdd(paramN, paramV); }

else //如果有相同的,一直删除取最后一个值为准

{ SortListRemove(paramN); SortListAdd(paramN, paramV); }

}

}

else //参数少于或等于1项

{

int equalindex = POSTStrIndexOf('=');

if (equalindex != -1)

{ //参数是1项

string paramN = POSTStrSubstring(0, equalindex);

string paramV = POSTStrSubstring(equalindex + 1);

SortListAdd(paramN, paramV);

}

else //没有传递参数过来

{ SortList = null; }

}

return SortList;

}

}

传递:

protected void Button1_Click(object sender, EventArgs e)

{

Encoding encode = SystemTextEncodingGetEncoding("utf-8");

byte[] arrB = encodeGetBytes("aa=aa&bb=好飞");

>

是post过去的数据还是aspx页面返回的数据?

如果是post过去的数据,在aspx用RequestForm["xxx"]来取,如果是aspx页面返回的数据你要clear一下,ResponseClear();ResponseWrite("xxxx");ResponseEnd();

如果你只是处理数据,不作显示的话,建议用ajax前台提交后台用一般处理程序也就是ashx来处理。

只需要返回<xml version='10' encoding='gb2312'><MASP_RESP><RESULT>0</RESULT><RESULT_MSG>婵€娲绘垚锷燂紒</RESULT_MSG></MASP_RESP>这些字符串,我应该怎样写返回值

我是这么写的 ResponseContentType = "text/xml";

//不要缓存

ResponseAppendHeader("Cache-Control", "max-age=0");

ResponseAppendHeader("Cache-Control", "no-cache");

ResponseWrite("<xml version='10' encoding='gb2312'>");

ResponseWrite("<MASP>");

ResponseWrite("<RESULT>200</RESULT>");

ResponseWrite("<CONTENT></CONTENT>");

ResponseWrite("</MASP>");

ResponseFlush();

返回来的结果

<xml version='10' encoding='gb2312'><MASP_RESP><RESULT>0</RESULT><RESULT_MSG>婵€娲绘垚锷燂紒</RESULT_MSG></MASP_RESP>(只要这段数据,后便的不想让客户端收到)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 10 Transitional//EN" ">

以上就是关于WP8 C# 如何post数据并获取返回值全部的内容,包括:WP8 C# 如何post数据并获取返回值、C#中使用post方法传参、ASP.NET POST如何返回数据等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9524803.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-29
下一篇 2023-04-29

发表评论

登录后才能评论

评论列表(0条)

保存