Old 10th May 2013, 14:36   #1
George02
Junior Member
 
Join Date: May 2013
Posts: 4
SHOUTcast Transcoder AJAX api Problem

I'am trying to create an application (in C# .NET Framework 4, Visual Studio) that make a simple request to api and retrive info .

code:
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create("http://myip:8000/api");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "?op=listplaylists&seq=45";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
rtbResponse.Text = responseFromServer;
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();



But I get an error "The server committed a protocol violation. Section=ResponseStatusLine"; at line "WebResponse response = request.GetResponse();"

Also trying to create a php page that make the same thing doesn't return nothing.

PHP Code:
<?php 
var url "http://myip:8000/api/";
var 
params "op=test&seq=45";
http.open("POST"urltrue);

http.setRequestHeader("Content-type""application/x-www-form-urlencoded; charset=UTF-8");
http.setRequestHeader("Content-length"params.length);
http.setRequestHeader("Connection""close");

http.onreadystatechange = function() {//Call a function when the state changes.
    
if(http.readyState == && http.status == 200) {
        
alert(http.responseText);
    }
}
http.send(params);
?>
No alert box show. I think the problem is from your api . What to do ?
George02 is offline   Reply With Quote
Old 10th May 2013, 22:03   #2
thinktink
Forum King
 
thinktink's Avatar
 
Join Date: May 2009
Location: No longer on the streets of Kings County, CA.
Posts: 3,087
No alert box shows because php is not JavaScript and also does not have an Ajax object.
thinktink is offline   Reply With Quote
Old 10th May 2013, 22:17   #3
DrO
 
Join Date: Sep 2003
Posts: 27,873
and there's no password details provided in the request and i wouldn't be surprised if it's not even been correctly configured in sc_trans to enable the support either.
DrO is offline   Reply With Quote
Old 11th May 2013, 06:00   #4
George02
Junior Member
 
Join Date: May 2013
Posts: 4
Quote:
Originally Posted by DrO View Post
and there's no password details provided in the request and i wouldn't be surprised if it's not even been correctly configured in sc_trans to enable the support either.
Thanks for your reply !

How can I do that? "configured in sc_trans to enable the support either" .


"and there's no password details provided in the request"
should I do something like :

code:

request.UseDefaultCredentials = false;
CredentialCache credential = new CredentialCache();
credential.Add(new Uri("http://myip:8000/api.php"),"Basic",new NetworkCredential("sc_trans|Username","sc_trans|Password");
request.Credentials = credential;

George02 is offline   Reply With Quote
Old 11th May 2013, 07:56   #5
George02
Junior Member
 
Join Date: May 2013
Posts: 4
Ok. So I reused to post data to API but ... the response is something like "?|?]???{??G>?f?4|?@??.

code:

MessageBox.Show((((HttpWebResponse)response).StatusDescription).ToString()); //message box show OK
dataStream = response.GetResponseStream();
StreamReader responseReader = new StreamReader(dataStream);
string XMLresponse = responseReader.ReadToEnd();

Dictionary<string, string> dict =
XElement.Parse(XMLresponse)
.Elements()
.ToDictionary(x => x.Name.LocalName, x => x.Value);

responseReader.Close();



What I'm doing wrong ? After I press ok to close messagebox my application freeze.
George02 is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Technical Support

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump