-
Couldn't load subscription status.
- Fork 0
add_json
timojaask edited this page Jul 10, 2014
·
5 revisions
Add new message to the database.
-
URL:
http://whispr.outi.me/api/add_json - Method: Post
- Arguments: Message object
- Return value: The ID of the new message
WARNING: At the moment the API is implemented so that when you post a new message, the "pubTime" is not the unix timestamp of when the message should be published, but a delay for publishing the message in seconds. So if you wanted to publish the message immediately, it would be "0".
##C#
// Create a new message object that will be sent to the server
var newMessage = new SkeneMessage() {
Latitude = 60.0,
Longitude = 20.0,
Text = "Hello, Skene!",
PublishTime = 1404066977 // 29.06.2014 @ 18:36 UTC
};
var httpClient = new HttpClient();
// Create the request URL
var uri = new Uri("http://whispr.outi.me/api/add_json");
// Create a JSON string from the new SkeneMessage object
var json = JsonConvert.SerializeObject(newMessage);
// Create HTTP content header with JSON string as it's data
var content = new StringContent(json);
// Set the content type to JSON
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Send the request and get a response
var response = await httpClient.PostAsync(uri, content);
// Read the received response, which should contain new message ID
var result = await response.Content.ReadAsStringAsync();