I'm currently trying to take a picture with my camera using this code. But I don't get a response.
I've already written the response, request function. My camera is in client mode. So if I start my application now and press the "Click" button, it should take a picture.
Public Class theta
Public THETA_ID As String = "name"
Public THETA_PASSWORD As String = "password"
Public THETA_IP As String = "XX"
Public THETA_URL As String = THETA_IP & "osc/"
Public response As String
Function post(osc_command As String) As String
Dim url = THETA_URL + osc_command
Dim request As Net.WebRequest = Net.WebRequest.Create(url)
request.Credentials = New Net.NetworkCredential(THETA_ID, THETA_PASSWORD)
Dim resp As Net.WebResponse = request.GetResponse()
End Function
The function should take a photo here.
Public Async Function takePicture() As Task(Of String)
Dim url = THETA_URL & "commands/execute"
Dim payload = New Dictionary(Of Object, Object) From {
{"name", "camera.takePicture"}
}
ServicePointManager.Expect100Continue = False
//Dim request As Net.HttpWebRequest = Net.HttpWebRequest.Create(url)
//request.Credentials = New Net.NetworkCredential(THETA_ID, THETA_PASSWORD)
Dim httpClientHandler = New HttpClientHandler() With {
.Credentials = New NetworkCredential("name", "password", "")
}
Dim x As New Http.HttpClient(httpClientHandler)
Dim content As New Net.Http.StringContent("{""name"": ""camera.takepicture""}",
System.Text.Encoding.UTF8, "application/json")
Dim response As Net.Http.HttpResponseMessage = Await x.PostAsync(url, content)
Dim result As String = Await response.Content.ReadAsStringAsync()
response = response
'Dim response As WebResponse = request.GetResponse()
End Function
This is the request.
Function SendRequest(actionstring As String) As XDocument
Dim url = THETA_URL & "commands/execute"
Dim postXml As XDocument = <?xml version='1.0'?>
<txtsig_request version='2.0'>
<credentials>
<api_username><%= THETA_ID %></api_username>
<api_password><%= THETA_PASSWORD %></api_password>
<client_id><%= "XX" %></client_id>
</credentials>
<%= XElement.Parse(actionstring) %>
</txtsig_request>
Dim postString As String = postXml.Declaration.ToString & postXml.ToString
Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
request.Method = "POST"
request.AllowWriteStreamBuffering = False
request.PreAuthenticate = True
request.ContentType = "application/xml"
request.ContentLength = postString.Length
request.KeepAlive = True
Dim outputstream As Stream = request.GetRequestStream()
Dim postBytes As Byte() = Encoding.ASCII.GetBytes(postString)
outputstream.Write(postBytes, 0, postBytes.Length)
Dim response As WebResponse = request.GetResponse()
Dim datastream As Stream = response.GetResponseStream()
Dim xd As XDocument = XDocument.Load(datastream, LoadOptions.None)
outputstream.Close()
response.Close()
Return xd
End Function
question from:
https://stackoverflow.com/questions/65951351/why-dont-i-get-any-response-from-my-camera 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…