Majid1101
(Majid1101)
7
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
namespace MapApi.Controllers
{
public class OSmController : ApiController
{
[HttpPost]
public async Task CreateNode()
{
string url = “http://192.168.43.177:8080/api/0.6/node/create”;
// Construct the XML payload
string xmlData = $@"
<osm>
<node lat=""33.642782"" lon=""73.077733"" version=""1"" changeset=""1"">
<tag k=""key1"" v=""value1""/>
<tag k=""key2"" v=""value2""/>
</node>
</osm>";
using (HttpClient client = new HttpClient())
{
// Create the HTTP content with XML payload
HttpContent content = new StringContent(xmlData, Encoding.UTF8, "application/xml");
// Make the POST request
HttpResponseMessage response = await client.PostAsync(url, content);
// Check if the request was successful
if (response.IsSuccessStatusCode)
{
return Ok("Node created successfully!");
}
else
{
return BadRequest("Failed to create node. Status code: " + response.StatusCode);
}
}
}
}
}
i’m using this code to create a node on Osm server locally but getting this error
StatusCode: 404, ReasonPhrase: ‘Not Found’, Version: 1.1, Content: System.Net.Http.StreamContent,