Couchdb 데이터베이스를 만드는 HTTP PUT 메서드를 가져 오는 데 문제가 있습니다. 코드에 대해 무서운 것은 없지만 전에 보았던 코드는 너무 지루하다. Connection 메서드가 Closed 인 경우 오류 메시지가 나타납니다. 뭔가를 알고 있어야합니다 .... 정말 이상한 것. Couchdb를 사용하여 새로운 DB를 만드는 컨텍스트에서 올바른 POST 메서드를 사용할 때 404가 표시됩니다. 어떤 도움을 많이 주셨습니다. HTTPWebRequest가 PUT 메소드를 수행 할 수 있습니까? 그렇다면 왜 안되는 지에 대해 당황 스럽습니다.Couchdb .... HttpWebRequest
자세한 내용은 다음과 같습니다. 기본 연결이 닫혔습니다 : 예기치 않게 연결이 닫혔습니다.
저는 Couchdb와 CURL을 확인했습니다 ... 괜찮습니다.
오류가이 시점에서 온다 ... 방법을 설정 한 후
Stream requestStream = httpWebRequest.GetRequestStream();
코드는 "PUT"로 :
private string DataViaHTTP(string url, Dictionary<string, string> parameters, string content, string contentType, int timeout, bool contentIsParam, string method)
{
byte[] requestData;
try
{
HttpWebRequest httpWebRequest;
if (contentIsParam == false)
{
requestData = System.Text.Encoding.ASCII.GetBytes(content);
httpWebRequest = (HttpWebRequest)WebRequest.Create(BuildParamString(url, parameters));
}
else
{
requestData = System.Text.Encoding.ASCII.GetBytes(BuildParamString(null, parameters));
httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
}
httpWebRequest.Method = method;
httpWebRequest.ContentType = contentType;
if (timeout > 0)
{
httpWebRequest.Timeout = timeout;
}
httpWebRequest.ContentLength = requestData.Length;
Stream requestStream = httpWebRequest.GetRequestStream();
requestStream.Write(requestData, 0, requestData.Length);
requestStream.Close();
// Read and return the response stream
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream outStream = httpWebResponse.GetResponseStream();
var stringStream = String.Empty;
using (StreamReader streamReader = new StreamReader(outStream))
{
stringStream = streamReader.ReadToEnd();
}
return stringStream;
}
catch (WebException e)
{
throw e;
}
catch (Exception e)
{
throw e;
}
}
이 작동하지 않았다 중 하나 :(
public string PutCommand(string url)
{
try
{
using (WebClient webclient = new WebClient())
{
webclient.Headers["User-Agent"] = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.89 Safari/532.5";
webclient.Encoding = System.Text.Encoding.ASCII;
var x = webclient.UploadData(url, "PUT", new byte[] {});
return System.Text.Encoding.ASCII.GetString(x);
}
}
catch (Exception e)
{
throw e;
}
}
코드가 지루하더라도 오류가 있어야합니다. – Femaref
내가 원한다면 ...... : – WeNeedAnswers
GET과 POST 둘 다 몇 년 동안 사용해온 동일한 코드 – WeNeedAnswers