求助.如何从.aspx的页面中获取到字符串..

wuliao789 2012-05-17 02:32:41
我跟老师做的虚拟环境..服务器端有个.aspx里面有Response.Write(Session("usersn"))这个字段..
我需要在客户端将Session("usersn")的值取到一个变量中并用于区分..请问如何完成?谢谢了..在下新手- -
...全文
227 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuliao789 2012-05-24
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]
引用 7 楼 的回复:

0 0哦哦..是这样啊..好的..我试试..谢谢

顺便问一下,你是在大学还是培训班?
[/Quote]
啊..大学.正在做毕业设计..但是没学过这个..所以做的很艰难..
fire_fire_fire 2012-05-17
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

0 0哦哦..是这样啊..好的..我试试..谢谢
[/Quote]
顺便问一下,你是在大学还是培训班?
wuliao789 2012-05-17
  • 打赏
  • 举报
回复
0 0哦哦..是这样啊..好的..我试试..谢谢
fire_fire_fire 2012-05-17
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

session.aspx的代码非常简单的- -

Partial Class session
Inherits System.web.UI.Page

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Response.Write(S……
[/Quote]
那你得到的就是类似于:张三|1|24 这样的字符串了?你解析它不就完了。

StringTokenizer st = new StringTokenizer(result, "|");
String[] strArray = new String[st.countTokens()];
int k = 0;
while (st.hasMoreTokens()) {
String temp = st.nextToken();
strArray[k] = temp;
k++;
}

strArray就是你从网络端获取的值了
或者你在网络端将返回的对象变成json字符串,android端反序列化一下对象也是一样的
小王爷 2012-05-17
  • 打赏
  • 举报
回复
一楼正解,我再加上getString()
public String getString(InputStream in) throws IOException {
StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = in.read(b)) != -1;) {
out.append(new String(b, 0, n));
}
return out.toString();
}
wuliao789 2012-05-17
  • 打赏
  • 举报
回复
session.aspx的代码非常简单的- -

Partial Class session
Inherits System.web.UI.Page

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Response.Write(Session("username")+"|")
Response.Write(Session("logintype")+"|")
Response.Write(Session("usersn"))
End Sub
End Class
wuliao789 2012-05-17
  • 打赏
  • 举报
回复
唔..具体是这样的.我这个程序取到一个字符串.然后作为url后缀(/login.aspx?xxx=xxxx这样)去访问一个login.aspx..login.aspx根据这个字符串和数据库进行对比来进行身份验证..同时得到session.aspx中的这个usersn..我这边需要做的是从session.aspx中获得这个usersn来作为一个参数..不知道描述是否清晰..就是说也不用get或者post去提交数据...
fire_fire_fire 2012-05-17
  • 打赏
  • 举报
回复
如果以上有用请结贴给分,谢谢
fire_fire_fire 2012-05-17
  • 打赏
  • 举报
回复
1.Response.Write()这个方法是在页面输出一段文本。如果是要给别的程序调用的话一般都会加上Response.End();
2.Asp.Net中Session的用法应该是这样:Session["usersn"]
3.如果有代码如下:

Session["username"] = "张三";
Response.Write(Session["username"]);
Response.End();
//执行完代码界面将输出:张三

4.如果有数据要提交,你可以用GET或POST方法提交数据,之后获得界面的返回,下面方法供参考

GET方法:
String urlString = baseUrlString + "?name=" + nameString + "&age="
+ ageString + "&type=1";
try {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(urlString);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream inputStream = httpEntity.getContent();
String str = getString(inputStream);
System.out.println(str);
} catch (Exception e) {
System.out.println("get:e=" + e.getMessage());
}


POST方法
try {
NameValuePair name = new BasicNameValuePair("name", nameString);
NameValuePair age = new BasicNameValuePair("age", ageString);
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(name);
list.add(age);
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(baseUrlString);
httpPost.setEntity(new UrlEncodedFormEntity(list, "utf-8"));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream inputStream = httpEntity.getContent();
String str = getString(inputStream);
System.out.println(str);
} catch (Exception e) {
System.out.println("e=" + e.getMessage());
}
trade_create_by_buyer-CSHARP-UTF-8 │ ├app_code ┈┈┈┈┈┈┈┈┈┈类文件夹 │ │ │ ├AlipayConfig.cs┈┈┈┈┈基础配置类文件 │ │ │ ├AlipayCore.cs┈┈┈┈┈┈支付宝接口公用函数类文件 │ │ │ ├AlipayNotify.cs┈┈┈┈┈支付宝通知处理类文件 │ │ │ ├AlipaySubmit.cs┈┈┈┈┈支付宝各接口请求提交类文件 │ │ │ └MD5.cs ┈┈┈┈┈┈┈┈┈MD5类库 │ ├log┈┈┈┈┈┈┈┈┈┈┈┈┈日志文件夹 │ ├default.aspx ┈┈┈┈┈┈┈┈支付宝接口入口文件 ├default.aspx.cs┈┈┈┈┈┈┈支付宝接口入口文件 │ ├notify_url.aspx┈┈┈┈┈┈┈服务器异步通知页面文件 ├notify_url.aspx.cs ┈┈┈┈┈服务器异步通知页面文件 │ ├return_url.aspx┈┈┈┈┈┈┈页面跳转同步通知文件 ├return_url.aspx.cs ┈┈┈┈┈页面跳转同步通知文件 │ ├Web.Config ┈┈┈┈┈┈┈┈┈配置文件(集成时删除) │ └readme.txt ┈┈┈┈┈┈┈┈┈使用说明文本 ※注意※ 需要配置的文件是: alipay_config.cs default.aspx default.aspx.csreturn_url.aspx return_url.aspx.cs notify_url.aspx notify_url.aspx.cs统一命名空间为:namespace Com.Alipiay ───────── 类文件函数结构 ───────── AlipayCore.cs public static Dictionary ParaFilter(SortedDictionary dicArrayPre) 功能:除去数组的空值和签名参数并以字母a到z的顺序排序 输入:SortedDictionary dicArrayPre 过滤前的参数组 输出:Dictionary 去掉空值与签名参数后的新签名参数组 public static string CreateLinkString(Dictionary dicArray) 功能:把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 输入:Dictionary dicArray 需要拼接的数组 输出:string 拼接完成以后的字符串 public static string CreateLinkStringUrlencode(Dictionary dicArray, Encoding code) 功能:把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对参数值做urlencode 输入:Dictionary dicArray 需要拼接的数组 Encoding code 字符编码 输出:string 拼接完成以后的字符串 public static void log_result(string sPath, string sWord) 功能:写日志,方便测试(看网站需求,也可以改成存入数据库) 输入:string sPath 日志的本地绝对路径 string sWord 要写入日志里的文本内容 public static string GetAbstractToMD5(Stream sFile) 功能:获取文件的md5摘要 输入:Stream sFile 文件流 输出:string MD5摘要结果 public static string GetAbstractToMD5(byte[] dataFile) 功能:获取文件的md5摘要 输入:byte[] dataFile 文件流 输出:string MD5摘要结果 ┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉ MD5.cs public static string Sign(string prestr, string key, string _input_charset) 功能:签名字符串 输入:string prestr 需要签名的字符串 string key 密钥 string _input_charset 编码格式 输出:string 签名结果 public static bool Verify(string prestr, string sign, string key, string _input_charset) 功能:验证签名 输入:string prestr 需要签名的字符串 string sign 签名结果 string key 密钥 string _input_charset 编码格式 输出:string 验证结果 ┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉ AlipayNotify.cs public Notify() 功能:构造函数 从配置文件初始化变量 public bool Verify(SortedDictionary inputPara, string notify_id, string sign) 功能:验证消息是否是支付宝发出的合法消息 输入:SortedDictionary inputPara 通知返回参数数组 string notify_id 通知验证ID string sign 支付宝生成的签名结果 输出:bool 验证结果 private string GetPreSignStr(SortedDictionary inputPara) 功能:获取待签名字符串(调试用) 输入:SortedDictionary inputPara 通知返回参数数组 输出:string 待签名字符串 private bool GetSignVeryfy(SortedDictionary inputPara, string sign) 功能:获取返回回来的待签名数组签名后结果 输入:SortedDictionary inputPara 通知返回参数数组 string sign 支付宝生成的签名结果 输出:bool 签名验证结果 private string GetResponseTxt(string notify_id) 功能:获取是否是支付宝服务器发来的请求的验证结果 输入:string notify_id 通知验证ID 输出:string 验证结果 private string Get_Http(string strUrl, int timeout) 功能:获取远程服务器ATN结果 输入:string strUrl 指定URL路径地址 int timeout 超时时间设置 输出:string 服务器ATN结果字符串 ┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉┉ AlipaySubmit.cs private static string BuildRequestMysign(Dictionary sPara) 功能:生成签名结果 输入:Dictionary sPara 要签名的数组 输出:string 签名结果字符串 private static Dictionary BuildRequestPara(SortedDictionary sParaTemp) 功能:生成要请求给支付宝的参数数组 输入:SortedDictionary sParaTemp 请求前的参数数组 输出:Dictionary 要请求的参数数组 private static string BuildRequestParaToString(SortedDictionary sParaTemp, Encoding code) 功能:生成要请求给支付宝的参数数组 输入:SortedDictionary sParaTemp 请求前的参数数组 Encoding code 字符编码 输出:string 要请求的参数数组字符串 public static string BuildRequest(SortedDictionary sParaTemp, string strMethod, string strButtonValue) 功能:建立请求,以表单HTML形式构造(默认) 输入:SortedDictionary sParaTemp 请求参数数组 string strMethod 提交方式。两个值可选:post、get string strButtonValue 确认按钮显示文字 输出:string 提交表单HTML文本 public static string BuildRequest(SortedDictionary sParaTemp) 功能:建立请求,以模拟远程HTTP的POST请求方式构造并获取支付宝的处理结果 输入:SortedDictionary sParaTemp 请求参数数组 输出:string 支付宝处理结果 public static string BuildRequest(SortedDictionary sParaTemp, string strMethod, string fileName, byte[] data, string contentType, int lengthFile) 功能:建立请求,以模拟远程HTTP的POST请求方式构造并获取支付宝的处理结果 输入:SortedDictionary sParaTemp 请求参数数组 string strMethod 提交方式。两个值可选:post、get string fileName 文件绝对路径 byte[] data 文件数据 string contentType 文件内容类型 int lengthFile 文件长度 输出:string 支付宝处理结果 public static string Query_timestamp() 功能:用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数 输出:string 时间戳字符串 ────────── 出现问题,求助方法 ────────── 如果在集成支付宝接口时,有疑问或出现问题,可使用下面的链接,提交申请。 https://b.alipay.com/support/helperApply.htm?action=supportHome 我们会有专门的技术支持人员为您处理

80,362

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧