Curl PUT data is not received

I'm trying to parse a file sent through http CURL PUT method. I'm using generic handler for parsing the file. I have created a generic handler for getting posted file. Following is the ASP.Net Code:

I'm not able to receive any file or contents. Do I have any problem in my code? Also following is the CURL script that is being used for sending file:

Please help me as it is very urgent for me. Thank you very much in advance.

public class Test : IHttpHandler {

public void ProcessRequest(HttpContext context)
{
    string result = string.Empty;
    try
    {
        context.Response.ContentType = "text/plain";
        //VALIDATE FILES IN REQUEST
        if (context.Request.Files.Count > 0)
        {
            try
            {
                //HANDLE EACH FILE IN THE REQUEST
                foreach (HttpPostedFile item in context.Request.Files)
                {
                    item.SaveAs(context.Server.MapPath("~/Temp/" + item.FileName));
                    context.Response.Write("FILE UPLOADED");
                }
            }
            catch (Exception ex)
            {
                //NO FILES IN REQUEST TO HANDLE
                context.Response.Write("ERROR: " + ex.Message);
            }
        }
        else
        {
            //NO FILES IN REQUEST TO HANDLE
            context.Response.Write("NO FILE(S) SENT");
        }

       context.Response.Write(result);
    }
    catch (Exception ex)
    {

        //result = "205";
        context.Response.Write(ex.Message);
    }
}

public bool IsReusable
{
    get
    {
        return false;
    }
}


function putRequest($url, $data)
{
    $putData = tmpfile();
    fwrite($putData, $data);
    fseek($putData, 0);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_INFILE, $putData);
    curl_setopt($ch, CURLOPT_INFILESIZE, strlen($data));
    curl_setopt($ch, CURLOPT_PUT, true);
    curl_exec($ch);
    $headers = curl_getinfo($ch);
    fclose($putData);
    curl_close($ch);
    return $headers['http_code'];
}

$url= " http://api.domain.com/upload/ ";
$data = "21.2,1000,1,2,3,4,5,6,7,8,9";
echo "Starting the put request
"; $ret = putRequest($url,$data); echo "Returned code: $ret
";
链接地址: http://www.djcxy.com/p/48604.html

上一篇: 使用curl从asp.net页面获取数据

下一篇: 未收到卷曲PUT数据