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

How to send and recieve a http webrequest ?


  • Please log in to reply
No replies to this topic

#1 Archimede

Archimede

    Member

  • Validating
  • PipPip
  • 15 posts

Posted 15 May 2016 - 08:41 PM

hello everybody :) ,
i took this code in internet to test a simple http request, but i have this exception: Eccezione first-chance di tipo 'System.Exception' in mscorlib.dll...
 
I am using netduino plus 2 .net micro framework 4.2
 
My goal is to send and to recieve the data from telegram's server(telegram is an application).
The code is the following:
 
using System;
using Microsoft.SPOT;
using System.Net;
using System.IO;
using System.Text;

 

 

class MyHttpRequest
    {
        public MyHttpRequest()
        {
            //nothing
        }
 
        public void Mymethod()
        {
           
            Debug.Print("Start...");
            // Create a request for the URL. 
           WebRequest request = WebRequest.Create("https://api.telegram.org/.....");  //here i have the exception
           
            // Get the response.
            WebResponse response = request.GetResponse();
           
// Display the status.
            Debug.Print(((HttpWebResponse)response).StatusDescription);
 
            // Get the stream containing content returned by the server.
            Stream dataStream = response.GetResponseStream();
 
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
 
            // Read the content.
            string responseFromServer = reader.ReadToEnd();  //here i have the error when use URL: http://www.google.it
         
            // Display the content.
            Debug.Print(responseFromServer);
 
            // Clean up the streams and the response.
            Debug.Print("end");
 
            reader.Close();
            response.Close();
        }
    }
 
Can i  use the WebRequest class if my URL is a https? :wacko:
 
because when i change the url(for example http://www.google.it)i have another exception : 
Eccezione first-chance di tipo 'System.ArgumentOutOfRangeException' in mscorlib.dll
 
if you can help me (if it is possible to write the code...) 
 
Thank you
 
Regards.





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.