ajax.request 跨域解决遇到问题

ascopi 2009-09-29 10:05:46
使用prototype的ajax.request来跨域提交数据,解决方法为:

先使用ajax.request 把数据post提交到本地一个页面 sendmsg.aspx
本地页面sendmsg.aspx获取ajax.request post过来的数据,然后自行使用程序进行跨域跳转提交。

但是会出错,httpwatch 检视的过程:
第一步进行跳转post方式
第二步出现错误Error 0x80070005,好像是拒绝访问,但是这步跳转跟ajax无关了,只是程序自行跳转(c#的代码,response.redirect),怎么会拒绝访问呢

不知道大家有什么解决办法
谢谢谢谢
...全文
326 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
twokickfoot 2009-09-29
  • 打赏
  • 举报
回复
ascopi 2009-09-29
  • 打赏
  • 举报
回复
解决了,不通过跳转方式提交,通过代码post的方式提交就可以
提供提交代码:
HttpWebRequest request;
request = (HttpWebRequest)WebRequest.Create(posturl);
request.Method="POST"; //Post请求方式
request.ContentType="text/html;charset=UTF-8"; //内容类型
string paraUrlCoded = System.Web.HttpUtility.UrlEncode("UTF-8"); //参数经过URL编码
byte[] payload;
payload = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(paraUrlCoded); //将URL编码后的字符串转化为字节
request.ContentLength = payload.Length; //设置请求的ContentLength
Stream writer = request.GetRequestStream(); //获得请求流
writer.Write(payload,0,payload.Length); //将请求参数写入流
writer.Close(); //关闭请求流

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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