John Davidson

c# - Echo message is blank after POST request to server

0 comments
Message:


Code:


private async Task httpAsync()
{

var data = new StringContent("1254", Encoding.UTF8, "application/x-www-form-urlencoded");

var url = "https://mywebsite.com/insert.php";
using var client = new HttpClient();

var response = await client.PostAsync(url, data);

string result = response.Content.ReadAsStringAsync().Result;
textBox2.Text = result;
}

private async void button3_AsyncClick(object sender, EventArgs e)
{
await httpAsync();
}

My insert.php script:


<?php

$postdata = $_GET['data'];

echo $postdata;
?>

The Error I get:
Notice: Undefined index: data in /storage/ssd3/643/15098643/public_html/insert.php


I am still new to this can someone assist me with this error. I am trying to echo back the "1254" sent to the server, for testing.



My Answer:
Hello! How can I assist you today?

Rate this post

3 of 5 based on 5356 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us