使用C#中的参数发送HTTP PUT请求

时间:2015-10-08 08:45:10

标签: c#

我在我的电脑上打开了一个tika服务器,我需要向它发送一个带有字符串参数的请求,该参数是我希望tika处理的文件的路径。我到目前为止的代码是:

private void getFromServer(string fileName)
{
    var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:9998/rmeta");
    httpWebRequest.Accept = "application/json";
    httpWebRequest.Method = "PUT";
    httpWebRequest.KeepAlive = true;

    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
    {
        string postData = @"C:\Users\######\Downloads\elasticsearch\elasticsearch-1.7.1.zip";
        byte[] byteArray = Encoding.ASCII.GetBytes(postData);

        string json = postData;

        streamWriter.Write(json);
    }
    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
    {
        var responseText = streamReader.ReadToEnd();
        //Now you have your response.
        //or false depending on information in the response
        console.write(responseText);
    }
}

问题是,服务器获取请求,但它返回我发送的字符串而不是相关文件的内容,我知道它可以工作,因为我使用cURL命令向它发送了相同的请求工作。我有什么想法我做错了吗?

PS主题标签代替我的用户名

0 个答案:

没有答案