Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

WebAPI and Socket


  • Please log in to reply
3 replies to this topic

#1 asciiman

asciiman

    Advanced Member

  • Members
  • PipPipPip
  • 56 posts
  • LocationTurkey

Posted 21 February 2015 - 10:18 AM

hi guys

 

I can use  "Get or Post" method with simple socket connection. I can send any parameters via url to "Get or Post" method. But i cant use [formBody] property.

 

What is wrong?

            var xSocket = new System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
            var xEndPoint = new System.Net.IPEndPoint(System.Net.Dns.GetHostEntry("127.0.0.1").AddressList[0], 80);

            xSocket.Connect(xEndPoint);
            xSocket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.Tcp, System.Net.Sockets.SocketOptionName.NoDelay, true);
            xSocket.SendTimeout = 1000;

            //byte[] xContent = System.Text.Encoding.UTF8.GetBytes("this is content");

            string xRequestLine = "Get /api/My/45 HTTP/1.1\r\n";

            string xHeaderLines =
                "Host: localhost" + "\r\n" +
                "Accept: text/json; charset=utf-8" + "\r\n" +
                "Accept-Encoding: gzip, deflate" + "\r\n" +
                //"Content-Type: application/json" + "\r\n" +
                //"Transfer-Encoding: chunked" + "\r\n" +
                "Connection: Close" + "\r\n" +
                //"Content-Length: " + xContent.Length.ToString() + "\r\n" +
                "\r\n";     // EmptyLine

            xSocket.Send(System.Text.Encoding.UTF8.GetBytes(xRequestLine));
            xSocket.Send(System.Text.Encoding.UTF8.GetBytes(xHeaderLines));
            //xSocket.Send(xContent);



#2 beastyboy

beastyboy

    Advanced Member

  • Members
  • PipPipPip
  • 194 posts
  • LocationNetherlands

Posted 21 February 2015 - 11:21 AM

Hi,

 

I think you should encode your byte array to for example base64.

 

So it is still string data.

 

Cheers 

Beasty,


Van SchOten Ict Diensten en Services
http://www.voids.nl


#3 asciiman

asciiman

    Advanced Member

  • Members
  • PipPipPip
  • 56 posts
  • LocationTurkey

Posted 21 February 2015 - 03:16 PM

hi sir 

I try it but dont working.

 

byte[] xContent = Convert.FromBase64String(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("this is content")));

 

I cant add .rar file

 

http://ul.to/ixhkmyn2



#4 asciiman

asciiman

    Advanced Member

  • Members
  • PipPipPip
  • 56 posts
  • LocationTurkey

Posted 23 February 2015 - 07:41 PM

hi

i fix it.

Content must be in   "  and  " 

 

for example

string xContent = "asdasdfaf" ;   is wrong   xContent = "\"asdasdfaf\"";  is true.

 

 

https://www.youtube....h?v=5WtRF5PkBe8






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.