compomics / ms2pip

MS²PIP: Fast and accurate peptide spectrum prediction for multiple fragmentation methods, instruments, and labeling techniques.
https://ms2pip.readthedocs.io
Apache License 2.0
35 stars 18 forks source link

problem with API using C# #209

Closed comics-asiis closed 6 months ago

comics-asiis commented 6 months ago

Hi,

I'm using C# to access MS2PIP webserver via the RESTful API. However, I immediately encountered an error when requesting a respond with the message: "500 Internal Server Error". I'm not sure if it comes to the different version of API, but I used the similar code to run MS2PIP via the V1 API successfully last year.

My current codes are as follows.

string postData = "{\"params\":{\"frag_method\":\"CID\",\"ptm\":[\"Oxidation,15.994915,M\"]},\"peptides\":{\"spec_id\":[\"peptide1\",\"peptide2\"],\"peptide\":[\"SLMK\",\"GSNLR\"],\"modifications\":[\"3|Oxidation\",\"-\"],\"charge\":[2,3]},\"options\":{\"add_retention_time\":false}}";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://iomics.ugent.be/ms2pip/api/v2/task");
request.Method = "POST";
using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
    streamWriter.Write(postData);
    streamWriter.Flush();
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
    responseFromServer = streamReader.ReadToEnd();
}

Thank you very much.

comics-asiis commented 6 months ago

Solved. For anyone who has this problem, maybe you could try setting the protocol version by adding: "request.ProtocolVersion = HttpVersion.Version10;"