我正在尝试在Visual Basic中制作测试许可证密钥系统。
有两个文本框。 **My AppRoutingModule:**
import { NgModule, Component } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AdminComponent } from './components/admin/admin.component';
import { HomeComponent } from './components/home/home.component';
import { ViewRegistrationComponent } from './components/view-registration/view-registration.component';
import { CallbackComponent } from './components/callback/callback.component';
import { AuthGuard } from './services/auth.guard';
const routes: Routes = [
{
path: '',
component: HomeComponent
},
{
path: 'admin/view/:id',
component: ViewRegistrationComponent,
canActivate: [AuthGuard]
},
{
path: 'admin',
component: AdminComponent,
canActivate: [AuthGuard]
},
{
path: 'callback',
component: CallbackComponent
}
];
...
**My authGard.ts**
import { CanActivate } from '@angular/router';
import { Injectable } from '@angular/core';
import { AuthService } from './auth.service';
@Injectable
export class AuthGuard implements CanActivate {
constructor(public authService: AuthService) {
}
canActivate() {
if (this.authService.isAuthenticated) {
return true;
} else {
this.authService.login();
}
}
}
bikeService.ts
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
@Injectable()
export class BikeService {
constructor(private http: HttpClient) { }
getBikes() {
const token = localStorage.getItem('access_token');
return this.http.get('/server/api/v1/bikes',
{headers: new HttpHeaders().set('Authorization', 'Bearer' + token)});
}
getBike(id: number) {
const token = localStorage.getItem('access_token');
return this.http.get('/server/api/v1/bikes', + id,
{headers: new HttpHeaders().set('Authorization', 'Bearer' + token)});
}
createBikeRegistration(bike) {
const body = JSON.stringify(bike);
return this.http.post('/server/api/v1/bikes/save', body, httpOptions);
}
}
具有许可证密钥,而TextBox1
具有名称。由于某种原因,这会引发错误:
TextBox2
错误:
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(insertlinkhere)
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim database As String = sr.ReadToEnd
If TextBox1.Text = "" Or TextBox1.Text = " " Or TextBox2.Text = "" Or TextBox2.Text = " " Then
MsgBox("Fill out the fields please.")
ElseIf database.Contains(":" & TextBox1.Text & ":" & TextBox2.Text & ":" & "Invalid:") Then
MsgBox("That key is not working anymore.")
ElseIf database.Contains(":" & TextBox1.Text & ":" & TextBox2.Text & ":" & Not "Invalid:") Then ' this lines raises the error
MsgBox("Congratulations!")
Else
MsgBox("Sorry, but that is not a valid product key. Please try again.")
End If
答案 0 :(得分:0)
看起来像下面 &不是“无效:”) 应该换成 &“不是无效:”)
答案 1 :(得分:0)
尝试这样的事情。
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(insertlinkhere)
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim database As String = sr.ReadToEnd()
Dim serialKey As String = TextBox1.Text.Trim()
Dim name As String = TextBox1.Text.Trim()
If String.IsNullOrEmpty(serialKey) Or String.IsNullOrEmpty(name) Then
MsgBox("Fill out the fields please.")
ElseIf database.Contains(":" & serialKey & ":" & name) Then
MsgBox(IIf(database.Contains("Invalid"), "That key is not working anymore.", "Congrats!"))
Else
MsgBox("Sorry, but that is not a valid product key. Please try again.")
End If