Below is the code for titanium:
var request = Titanium.Network.createHTTPClient();
request.open("POST", bh.serverAddress + "MyCareer.svc/PostMessage/"+ bh.userID + "/" + bh.logic.profile.userID);
request.setRequestHeader("enctype", "multipart/form-data");
request.setRequestHeader("Content-Type", "text/json");
request.send(data_to_send);
request.onload = function() {
Ti.API.info(this.responseText);
bh.ui.profile.createWindow();
};
request.onerror = function(){
alert('Error while posting message');
};
Below is the code for WCF:
Interface:
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "/PostMessage/{userid}/{touserid}",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
int PostMessage(string userid, string touserid, string message);
Class:
public int PostMessage(string userID, string toUserID, string message)
{
MDBDataContext oMDB = new MDBDataContext();
int returnValue = oMDB.PostMessage(Convert.ToInt32(userID), message, Convert.ToInt32(toUserID));
oMDB.Dispose();
return returnValue;
}
Query: If i convert this functionality to “GET” than it works very fine. But, with “POST” i get error and i am unable to figure out the error. I have enable traceListener also for WCF, but no error there.
Please help. I am stuck at this point. I am trying with iPhone simulator.
Finally, i found the problem in my code. And this solution apply to every client side technology.
Let’s see the working code first:
Fixes:
Hope that helps. whole point is that what you deem is correct for javascript is not correct for json.