将数据从一个asp.net应用程序发布到另一个asp.net应用程序 [英] Post data from one asp.net application to anther asp.net application

查看:77
本文介绍了将数据从一个asp.net应用程序发布到另一个asp.net应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,请帮助我将数据从一个asp.net网站发布到另一个asp.net网站,我使用带有cookie的http-post方法,但是我无法将数据发布到文件上传器,请为我提供帮助将数据发布到另一页的页面(在我必须发布数据的另一页上,有两个文本框,一个文件上传器,两个下拉列表和一个提交按钮).
在此先感谢.

我用过的代码----




hi to all, please help me for Posting data from one asp.net website to another asp.net website, i have use http-post method with cookies, but i cannont post data to file-uploader, please help me for posting the data to a page of another page (and at the another page at which i have to post data there are ,two textboxes,one file-uploader, two drop-downlists and one submit button).
thanks in advance.

My used Code----




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

public partial class nurse : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        cvbrowserPostData();
    }
    public void cvbrowserPostData()
    {
        string ResumePath = Server.MapPath("Doc1.docx");
        string boundary = Guid.NewGuid().ToString();
        CookieContainer cookies = new CookieContainer();
        string url = "https://www.test.com/JobSeeker/PostNewResume.aspx?sslRedirectCnt=1";//not real url

        string resume = Server.MapPath("Doc1.docx");
     
        HttpWebRequest request = HttpWebRequest.Create(url)
            as HttpWebRequest;
        request.Method = "POST";
        request.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
        request.PreAuthenticate = true;
        request.CookieContainer = cookies;
        StringBuilder sb = new StringBuilder();

        //sb.AppendFormat("--{0}", boundary);
        //sb.AppendFormat("\r\n");
        //sb.AppendFormat("Content-Disposition: form-data; name=\"a_aid\"");
        //sb.AppendFormat("\r\n");
        //sb.AppendFormat("\r\n");
        //sb.AppendFormat("cv-mate");
        //sb.AppendFormat("\r\n");


  

        sb.AppendFormat("--{0}", boundary);
        sb.AppendFormat("\r\n");
        sb.AppendFormat("Content-Disposition: form-data; name=\"ucResumeUpload:tbJobTitle\"");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("developer");
        sb.AppendFormat("\r\n");




        sb.AppendFormat("--{0}", boundary);
        sb.AppendFormat("\r\n");
        sb.AppendFormat("Content-Disposition: form-data; name=\"ucResumeUpload:tbLocation\"");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("sw13 9ru");
        sb.AppendFormat("\r\n");



        sb.AppendFormat("--{0}", boundary);
        sb.AppendFormat("\r\n");
        sb.AppendFormat("Content-Disposition: form-data; name=\"btnContinue\"");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("Continue");
        sb.AppendFormat("\r\n");





        sb.AppendFormat("--{0}", boundary);
        sb.AppendFormat("\r\n");
        sb.AppendFormat("Content-Disposition: form-data; name=\"ucResumeUpload:newFileUpload:inputResumeUpload\"; filename=\"" + Path.GetFileName(resume) + "\"");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("Content-Type: application/msword");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("\r\n");
        using (FileStream fs = new FileStream(resume, FileMode.Open, FileAccess.Read))
        {
            byte[] contents = new byte[fs.Length];
            fs.Read(contents, 0, contents.Length);
            sb.Append(Encoding.Default.GetString(contents));
        }
        sb.AppendFormat("\r\n");


             sb.AppendFormat("--{0}", boundary);
        sb.AppendFormat("\r\n");
        sb.AppendFormat("Content-Disposition: form-data; id=\"spanFilename\"");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("test.docx");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("--{0}", boundary);
        sb.AppendFormat("\r\n");
        sb.AppendFormat("Content-Disposition: form-data; name=\"ucResumeUpload:TargetLevel1:ddlLevel\"");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("SNCAREERLEVEL0");
        sb.AppendFormat("\r\n");



        sb.AppendFormat("--{0}", boundary);
        sb.AppendFormat("\r\n");
        sb.AppendFormat("Content-Disposition: form-data; name=\"ucResumeUpload:TargetSpecialism1:ddlSpecialism\"");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("SNSPECIALISM0");
        sb.AppendFormat("\r\n");

        sb.AppendFormat("--{0}", boundary);
        sb.AppendFormat("\r\n");
        sb.AppendFormat("Content-Disposition: form-data; name=\"btnContinue\"");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("\r\n");
        sb.AppendFormat("Continue");
        sb.AppendFormat("\r\n");


        byte[] fulldata = Encoding.Default.GetBytes(sb.ToString());
        request.ContentLength = fulldata.Length;
        using (Stream sw = request.GetRequestStream())
        {
            sw.Write(fulldata, 0, fulldata.Length);
        }
        HttpWebResponse response = request.GetResponse() as HttpWebResponse;
        using (StreamReader sr = new StreamReader(response.GetResponseStream()))
        {
            HttpContext.Current.Response.Write(sr.ReadToEnd());
            string ss = sr.ReadToEnd();
        }
    }
}

推荐答案

请参阅我对答案的评论.

这是第一个引起关注的问题:方案为"http"或"https"的URI在哪里?您正在使用string url = "test@url.com";,它不能是网页URI.仅当您当前在运行中的HTTP服务器上确实已有通过HTTP或HTTPS协议运行的网页时,才可以使用HttpWebRequest上载文件;否则,您可以使用HttpWebRequest上载文件.并且此页面应具有能够接收POST数据并可以对此数据进行处理的服务器端代码.

在显示的代码中,另一个ASP.NET应用程序"根本不存在.

您的问题提出了另一个问题:您是否真正了解HTTP的功能以及Web的工作方式?在我看来,您需要了解它.我什至都不知道,甚至可能从头开始学习.

祝你好运,
—SA
Please see my comment to the answer.

This is the first problem which catch an eye: where is the URI with the scheme "http" or "https"? You are using string url = "test@url.com"; which cannot be a Web page URI. You can upload the file with HttpWebRequest only if your have really existing Web page working through HTTP or HTTPS protocol on a currently running HTTP server; and this page should have the server-side code capable of receiving POST data and doing something with this data.

In the code you show, that "another ASP.NET application" simply does not exist.

Your question raises another question: do you really understand what HTTP does and how the Web works? It seems to me you need to learn about it; I don''t even know what, maybe even learn from scratch.

Good luck with that,
—SA


这篇关于将数据从一个asp.net应用程序发布到另一个asp.net应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆