I am struggling with sending a POST to an HTTP server that is internal and can only be accessed via SSH from the outside.
What I'm doing is simply entering a number into a textbox then converting it to a byte to be sent with a POST. From the standpoint of the SSH connection it works fine. It's just that it hangs and does nothing after connecting. I'm pretty new to coding something like this.
- protected void Button1_Click(object sender, EventArgs e)
- {
- var data = new
- {
- Number = Number.Text,
- };
- string stringdata = JsonConvert.SerializeObject(data);
- byte[] bytedata = Encoding.ASCII.GetBytes(stringdata);
- Button1.Enabled = true;
- SSHSubmits.SIDSubmitByte(bytedata);
- }
Then sending it to a function
- public static void SIDSubmitByte(byte[] fromSource)
- {
- using (var sshClient = ClientCreate())
- {
- sshClient.Connect();
- Httpsend(fromSource).Wait();
- sshClient.Disconnect();
- }
- }
The Httpsend looks like this
- private static async Task<string> Httpsend(byte[] fromSource)
- {
- string consortiumPostAddr = "http://127.0.0.1:42069/incoming/1/1/testsid";
- HttpClient httpclient = new HttpClient();
- ByteArrayContent byteContent = new ByteArrayContent(fromSource);
- await Task.Delay(3000);
- var response = await httpclient.PostAsync(consortiumPostAddr, byteContent);
- string result = response.Content.ReadAsStringAsync().Result;
- httpclient.Dispose();
- return result;
- }