dpu66046 2017-05-18 16:08 采纳率: 0%
浏览 99

HTTPWebRequest文件从内存上传

I want to send data to my web server from my windows application. Firstly i was sending data with URL parameters but due to URL lenght limit it was failing with large data. Then i tried to send data like file uploads but my data is not a file. It is very long string(about 4k chars). So file upload tutorials on internet i replaced FileStream with my byte array but on server side $_FILES variable is an empty array. Here is my code.

Sub sendData(ByVal data As String)

    Dim enc_data As String = EncryptRJ256(data)
    Dim byteData() As Byte = Encoding.UTF8.GetBytes(enc_data)

    Dim postReq As HttpWebRequest = WebRequest.Create("http://example.com")
    postReq.Method = "POST"
    postReq.KeepAlive = True
    postReq.AllowWriteStreamBuffering = True
    postReq.ContentLength = byteData.Length

    Dim postreqstream As Stream = postReq.GetRequestStream()
    postreqstream.Write(byteData, 0, byteData.Length)
    postreqstream.Close()


    Dim postresponse As HttpWebResponse
    postresponse = postReq.GetResponse()
    Dim postreqreader As New StreamReader(postresponse.GetResponseStream())

    Dim thepage As String = postreqreader.ReadToEnd
    File.WriteAllText("C:\Users\kenar\Desktopesponse.txt", thepage)
End Sub

There is nothing to show on server side. I'm using apache web server and checking $_FILES variable on PHP script.

  • 写回答

1条回答 默认 最新

  • dsfsad089111 2017-05-18 16:37
    关注

    It doesn't appear that you're uploading a file, I suggest trying to check your $_POST instead for data, as i'm guessing before you was checking $_GET. If you want to submit as a file you would have to set the appropriate content type as well.

    评论

报告相同问题?

悬赏问题

  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题