Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net BC30188:预计申报;新的NetworkCredential VB.NET_Asp.net_Vb.net_Apple Push Notifications_Urbanairship.com - Fatal编程技术网

Asp.net BC30188:预计申报;新的NetworkCredential VB.NET

Asp.net BC30188:预计申报;新的NetworkCredential VB.NET,asp.net,vb.net,apple-push-notifications,urbanairship.com,Asp.net,Vb.net,Apple Push Notifications,Urbanairship.com,在做了几年的兼职编程(12年的经典ASP)之后,我开始做更多的编程,结果我自学了.net 我正试图使用UrbanAirship的API通过苹果的推送通知服务器(APNS)发送测试推送通知。我找到了这个示例代码,但是我很难实现它 我收到错误:BC30188:预期声明。以下是这一行的代码: req.Credentials = New NetworkCredential("username", "password") 这是我的全部代码: pushvb.aspx pushvb\u bg.aspx.v

在做了几年的兼职编程(12年的经典ASP)之后,我开始做更多的编程,结果我自学了.net

我正试图使用UrbanAirship的API通过苹果的推送通知服务器(APNS)发送测试推送通知。我找到了这个示例代码,但是我很难实现它

我收到错误:BC30188:预期声明。以下是这一行的代码:

req.Credentials = New NetworkCredential("username", "password")
这是我的全部代码:

pushvb.aspx

pushvb\u bg.aspx.vb

Imports System   
Imports System.Net  
Imports System.Text  
Imports System.IO  
Imports System.WinForms  

Namespace UrbanAirship  
public partial Class uacode  
    Inherits System.Web.UI.Page  
    Public Const testing As String = "testing..."  
    Dim req As WebRequest = WebRequest.Create("https://go.urbanairship.com/api/push/")  
    Dim postData As String = "{""aps"": {""badge"": ""+1"", ""alert"": ""pushvb"",""sound"": ""default"",""device_tokens"": ""token""}}"  
    req.Credentials = New NetworkCredential("username", "password")  
    req.Method = "POST"  
    Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)  
    req.ContentType = "application/json"  
    req.ContentLength = byteArray.Length  
    Dim dataStream As Stream = req.GetRequestStream()  
    dataStream.Write(byteArray, 0, byteArray.Length)  
    dataStream.Close()  
    Dim resp As WebResponse = req.GetResponse() 
    dataStream = resp.GetResponseStream()  
    Dim reader As New StreamReader(dataStream)  
    Dim responseFromServer As String = reader.ReadToEnd()  
    Console.WriteLine(responseFromServer)  
    reader.Close()  
    dataStream.Close()  
    req.Close()  
end Class  
end Namespace  


任何帮助都将不胜感激。非常感谢您抽出时间查看。

嗯。。。答案很简单。在方法之外,只允许声明。您需要在类中创建一个从您处调用的方法,或者是页面加载事件

带有dim和new的行被接受为声明,Public Const也是声明


req.Credentials=New NetworkCredential(“用户名”、“密码”)
是代码中的第一行,它不是一个声明,而是一个分配,因此会显示在错误窗口中。

感谢您的帮助!我重新构造了代码,并从那里开始工作。